Java小程序-显示当前时间

System.currentTimeMillis()    返回从GMT 1970年1月1日00:00:00开始到当前时刻的毫秒数

时间戳是时间开始计时的点,因为1970年是UNIX操作系统正式发布的时间,所以也称 UNIX时间戳(UNIX epoch)

public class ShowCurrentTime {// 显示当前时间
	public static void main(String[] arg) {
		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 = totalHours % 24;
		System.out.println("Current time is " + currentHour + " : " + currentMinute + " : " + currentSecond + " GMT");
	}
}

猜你喜欢

转载自blog.csdn.net/qq_326324545/article/details/80894460