简体   繁体   中英

how can i display current time in java using currentTimeMillis() method

i want to create a java program that displays the current time in GMT timezone using System.currentTimeMillis() method.

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);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM