您的位置:首页 > 编程语言 > Java开发

Java语言程序设计 第二章(2.8)

2018-03-21 21:33 253 查看
2.8    (当前时间)写出显示当前格林威治时间的程序。提示用户输入相对于GMT的时区偏移量,然后显示在这个特定时区的时间。import java.util.Scanner;

public class ShowCurrentTime
{
public static void main(String[] args)
{
Scanner inPut = new Scanner(System.in);
//compute the GMT

long totalMilliSeconds = System.currentTimeMillis();
//compute the total seconds
long totalSeconds = totalMilliSeconds/1000;
//compute the current second
long currentSecond = totalSeconds%60;
//compute the total minutes
long totalMinutes = totalSeconds/60;
//compute the current minute
long currentMinute = totalMinutes%60;
//compute the hours
long totalHours = totalMinutes/60;
//compute the current hour
long currentHour = totalHours%24;

//conversion time zone
int timeZone = inPut.nextInt();
long currentTimeZoneHour = currentHour+timeZone;

//display result
System.out.println("The current time is "+currentTimeZoneHour+":"+currentMinute+":"+currentSecond);

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Chapter 2 Elementary