如何使用currentTimeMillis()方法在java中显示当前时间

时间:2017-03-11 14:12:54

标签: java methods

我想创建一个java程序,使用System.currentTimeMillis()方法以GMT时区显示当前时间。

public class DisplayTime {
    public static void main(String[] args){

        long totalMilliSeconds = System.currentTimeMillis();
        long totalSeconds = totalMilliSeconds / 1000;
        long currentSecond = totalSeconds % 60;
        long totalMinutes = totalSeconds / 60;
        long currentMinute = totalMinutes % 60;
        long totalHours = totalMinutes / 60;
        long currentHour = totalMinutes % 12;
        System.out.println(currentHour + " : " + currentMinute + " : " + currentSecond);
    }
}

1 个答案:

答案 0 :(得分:0)