- public class ShowCurrentTime
- {
- public static void main(String[] args)
- {
- //Obtain the total milliseconds since midnight,Jan 1,1970
- 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;
- long tempHour = totalHours%24;
- if (tempHour<15&&tempHour>0)
- {
- currentHour = tempHour+8;
- }
- else
- {
- currentHour = tempHour-16;
- }
- System.out.println("Current time is "+ currentHour +
- ":"+currentMinute +":"+currentSecond+
- "GMT");
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/0112201411125.html
来源: http://www.codesnippet.cn/detail/0112201411125.html