码迷,mamicode.com
首页 > 其他好文 > 详细

HW2.25

时间:2016-08-08 22:32:53      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 1 import java.util.Scanner;
 2 
 3 public class Solution
 4 {
 5     public static void main(String[] args)
 6     {
 7         Scanner input = new Scanner(System.in);
 8         System.out.print("Enter the time zone offset to GMT: ");
 9         int offset = input.nextInt();
10 
11         input.close();
12 
13         long totalMilliseconds = System.currentTimeMillis();
14         long totalSeconds = totalMilliseconds / 1000;
15         long currentSecond = totalSeconds % 60;
16         long totalMinutes = totalSeconds / 60;
17         long currentMinute = totalMinutes % 60;
18         long totalHours = totalMinutes / 60;
19         long currentHour = totalHours % 24;
20 
21         long currentHourWithOffset = currentHour + offset;
22         
23         if(currentHourWithOffset < 0)
24             currentHourWithOffset += 24;
25         else if(currentHourWithOffset > 23)
26             currentHourWithOffset -= 24;
27 
28         System.out.println("The current time is " + currentHourWithOffset + ":" + currentMinute 
29             + ":" + currentSecond);
30     }
31 }

 

HW2.25

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5750940.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!