*2.8(当前时间)程序清单2-7给出了显示当前格林尼治时间的程序。修改这个程序,提示用户输入相对于GMT的时区偏移量,显示在这个特定时区的时间
题目
题目描述
*2.8(当前时间)程序清单2-7给出了显示当前格林尼治时间的程序。修改这个程序,提示用户输入相对于GMT的时区偏移量,显示在这个特定时区的时间
运行示例
Enter the time zone offset to GMT: -5
The current time is 4:50:34
程序清单2-7(非本题代码)+思路(注释)
public class ShowCurrentTime {
public static void main(String[] args) {
// 2.8可以在这里获取时区
// Obtain the total milliseconds since midnight, Jan 1, 1970
long totalMilliseconds = System.currentTimeMillis();
// Obtain the total seconds since midnight, Jan 1, 1970
long totalSeconds = totalMilliseconds / 1000;
//2.8可以在这里将求出的秒数+时区和GMT时区的偏移(秒数)
// Compute the current second in the minute in the hour