[問題] JAVA時間顯示錯誤
教科書的內容是 顯現現在的時間 可是我照著打 為什麼時間會出錯?
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
推
03/02 23:43,
5年前
, 1F
03/02 23:43, 1F
推
03/03 17:47,
5年前
, 2F
03/03 17:47, 2F
→
03/03 17:49,
5年前
, 3F
03/03 17:49, 3F
→
03/04 14:29,
5年前
, 4F
03/04 14:29, 4F
→
03/05 16:08,
5年前
, 5F
03/05 16:08, 5F
→
03/05 16:09,
5年前
, 6F
03/05 16:09, 6F
Programming 近期熱門文章
PTT數位生活區 即時熱門文章