作者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://www.ptt.cc/bbs/Programming/M.1551535190.A.2D3.html
推 ray2501: Time zone 114.41.65.227 03/02 23:43
推 LPH66: 起點時間的 1970/1/1 半夜是 UTC+0 時間 1.200.193.140 03/03 17:47
→ LPH66: 也就是這個 0 是 UTC+0 的午夜 1.200.193.140 03/03 17:49
→ RicciYeh: 謝謝回覆 123.51.170.192 03/04 14:29
→ MOONRAKER: 是不知道有時區是嗎 220.135.118.23 03/05 16:08
→ MOONRAKER: 連時區名稱都顯示給你看 220.135.118.23 03/05 16:09