作者RicciYeh (RicciYeh)
看板Programming
标题[问题] JAVA时间显示错误
时间Sat Mar 2 21:59:48 2019
教科书的内容是 显现现在的时间 可是我照着打 为什麽时间会出错?
public class ShowCurrentTime{
public static void main(String[] args){
// obtain the total milliseconds since midnight, jan 1, 1970
long totalMilliseconds = System.currentTimeMillis();
// obtain the total seconds since midnight, jan 1, 1970
long totalSeconds = totalMilliseconds / 1000;
// Compute the current second in the minute in the hour
long currentSecond = totalSeconds % 60;
// Obtain the titak minutes
long totalMinutes = totalSeconds / 60;
// Compute the current minute in the hour
long currentMinute = totalMinutes % 60;
// Obtain tje total hours
long totalHours = totalMinutes / 60;
// Compute the current Hour
long currentHour = totalHours % 24;
// 这行是我自己上网找的 确定一下我的时间
System.out.print("Current time is "+new java.util.Date( System.currentTimeMillis() )+"\n");
// Display results
System.out.println("Current time is " + currentHour + ":" + currentMinute + ":" + currentSecond + " GMT");
}
}
输出:
Current time is Sat Mar 02 21:55:39 CST 2019
Current time is 13:55:39 GMT
想请问各位大神这个是哪里出错?
--
Sent from my Windows
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.164.88.119
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Programming/M.1551535190.A.2D3.html
1F:推 ray2501: Time zone 114.41.65.227 03/02 23:43
2F:推 LPH66: 起点时间的 1970/1/1 半夜是 UTC+0 时间 1.200.193.140 03/03 17:47
3F:→ LPH66: 也就是这个 0 是 UTC+0 的午夜 1.200.193.140 03/03 17:49
4F:→ RicciYeh: 谢谢回覆 123.51.170.192 03/04 14:29
5F:→ MOONRAKER: 是不知道有时区是吗 220.135.118.23 03/05 16:08
6F:→ MOONRAKER: 连时区名称都显示给你看 220.135.118.23 03/05 16:09