首页 > 试题广场 >

(当前时间)程序清单2-7 给出了显示当前格林威治时间的程

[问答题]
 (当前时间)程序清单2-7 给出了显示当前格林威治时间的程序。修改这个程序,提示用户输入相 对于 GMT的时区偏移量,然后显示在这个特定时区的时间。下面是一个运行示例: 

这是啥知识点?🤔🤔🤔
发表于 2021-03-31 17:59:55 回复(0)
import java.util.Scanner;

public class Test2_8 {
    public static void main(String[] args) {

        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");


        Scanner input = new Scanner(System.in);
        System.out.println("Enter the time zone offset to GMT: ");
        int offset = input.nextInt();
        long offsetGMT =(currentHour + offset) + currentMinute + currentSecond;
        System.out.println("The current time is " + (currentHour + offset) + ":" + currentMinute + ":" + currentSecond + " GMT");

    }
}

发表于 2020-11-12 14:39:33 回复(0)