public class ShowCurrentTime { public static void main(String[] args) {
//获得从1970年1月1日0点到当前时间之间单位为毫秒的差值
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 % 60;
//输出结果
System.out.println("Current time is " + currentHour + ":"
+ currentMinute + ":" + currentSecond + "GMT");
}}
//获得从1970年1月1日0点到当前时间之间单位为毫秒的差值
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 % 60;
//输出结果
System.out.println("Current time is " + currentHour + ":"
+ currentMinute + ":" + currentSecond + "GMT");
}}
解决方案 »
- 使用mybatis.bat报错,新手。
- struts1的bean:include问题
- strict servlet API: cannot call getWriter() after getOutputStream()
- schemaProvider.getTables() failed 怎么回事
- 询问apache项目信息
- 我安装了MYeclipse和eclipse2.13无法启动tomcat5试运行程序。
- 在java中native这个关键子是作什么用的,一定给分
- 存储过程的问题
- java读取xml文件的几个问题!请关注
- 北京java项目外包承接工作室成立,可业余做项目,将统一安排。
- junit 怎么获得session值
- 额问个正则表达式的问题只能输入26额字母大小写和数字的
修改之后的(关于时区偏移量):
import java.util.Scanner;public class Exercise2_25 {
public static void main(String[] args) {
// Prompt the user to enter the time zone offset to GMT
Scanner input = new Scanner(System.in);
System.out.print("Enter the time zone offset to GMT: ");
long timeZoneOffset = input.nextInt();
// Obtain the total milliseconds since the midnight, Jan 1, 1970
long totalMilliseconds = System.currentTimeMillis(); // Obtain the total seconds since the midnight, Jan 1, 1970
long totalSeconds = totalMilliseconds / 1000; // Compute the current second in the minute in the hour
long currentSecond = totalSeconds % 60; // Obtain the total minutes
long totalMinutes = totalSeconds / 60; // Compute the current minute in the hour
long currentMinute = totalMinutes % 60; // Obtain the total hours
long totalHours = totalMinutes / 60; // Compute the current hour
long currentHour = (totalHours + timeZoneOffset) % 24; // Display results
System.out.println("Current time is " + currentHour + ":"
+ currentMinute + ":" + currentSecond);
}