📄 exercise6_7.java
字号:
public class Exercise6_7 {
public static void main(String[] args) {
Time time = new Time();
System.out.println("Hour: " + time.getHour() + " Minute: " +
time.getMinute() + " Second: " + time.getSecond());
}
}
class Time {
private int hour;
private int minute;
private int second;
public Time() {
// Obtain the total seconds since the midnight, Jan 1, 1970
long totalSeconds = System.currentTimeMillis() / 1000;
// Compute the current second in the minute in the hour
second = (int) (totalSeconds % 60);
// Obtain the total minutes
long totalMinutes = totalSeconds / 60;
// Compute the current minute in the hour
minute = (int) (totalMinutes % 60);
// Obtain the total hours
long totalHours = totalMinutes / 60;
// Compute the current hour
hour = (int) (totalHours % 24);
}
public String toString() {
return hour + ":" + minute + ":" + second + " GMT";
}
public int getHour() {
return hour;
}
public int getMinute() {
return minute;
}
public int getSecond() {
return second;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -