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);
}
}
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);
}
}
相关文章推荐
- Java语言程序设计 第二章 (2.2)
- Java语言程序设计-基础篇-第八版-编程练习题-第二章
- Java语言程序设计 第二章(2.5)
- Java语言程序设计基础篇原书第十版第二章编程练习题答案
- Java语言程序设计 第二章(2.6)
- Java语言程序设计 第二章 (2.3)
- java语言程序设计基础课后习题第二章
- Java语言程序设计-基础篇-第八版-第二章
- Java语言程序设计 第二章(2.7)
- Java语言程序设计-基础篇第二章基本程序设计
- Java语言程序设计-基础篇-第八版-复习题-第二章
- Java语言程序设计 第二章 (2.4)
- 梁勇Java语言程序设计第三章全部例题 为第五次作业
- Java语言程序设计-基础篇-第八版-复习题-第四章
- Java学习笔记 第二章 Java语言基础
- 【JAVA语言程序设计基础篇】--图形--练习绘制时钟
- Java 语言程序设计课件【1~7章】(Word版)
- 第二章 java语言基础
- Java语言程序设计-基础篇-5.6习题-显示模式
- 关于学习JAVA程序设计语言的回顾与展望