package chaper2;
import java.util.Scanner;
/**
* 程序清单2-7给出了显示当前格林威治时间的程序。
* 修改这个程序,提示用户输入相 对于 GMT 的时区偏移量,然后显示在这个特定时区的时间。
* @author siyihe
* @create 2022-06-23 14:52
* @project javaexec0
*/
public class Skewing {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.println("Enter the time zone offset to GMT:");
int offset=input.nextInt();
//获取当前的格林威治时间的毫秒数
long totalMiliseconds=System.currentTimeMillis();
//转换成实际的秒数
long seconds=totalMiliseconds/1000;
//获取时间的秒数
long factSeconds=seconds%60;
//转换的时间的分钟数
long minutes=totalMiliseconds/60;
//获取时间的分钟数
long factMinutes=minutes%60;
//转换时间的小时数
long hours=minutes/60;
//获取当前时区的小时数(24小时制)
long factHours=(hours+offset)%24;
System.out.println("The current time is "+factHours+":"+factMinutes+":"+factSeconds);
}
}
用户输入相 对于 GMT 的时区偏移量,然后显示在这个特定时区的时间
最新推荐文章于 2024-03-28 14:15:55 发布