Calculate current time

The code is as follows:

/*Practice calculating the current time using system Currenttimemillis() calculates the current time system Currenttimemillis() can return the time difference between the current time and midnight coordinated universal time on January 1, 1970 * / class demo4 {public static void main (string [] args) {/ / save the milliseconds from midnight on January 1, 1970 to the present in a variable long summillis = system. Currenttimemillis() ; // Total seconds long sumseconds = summillis / 1000// Current seconds long currentsecond = sumseconds% 60// Total minutes long summinutes = sumseconds / 60// Current minutes long currentminute = summinutes% 60// Total hours long sumhours = summinutes / 60// Current hours long currenthours = sumhours% 24// Calculate Beijing time long beijinghour = (currenthours + 8)% 24; System. out. println(beijingHour+":"+currentMinute+":"+currentSecond); } }

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>