我有一個函數會輸出yyyy/mm/dd hh:mm:ss。除了小時之外,一切都非常準確,似乎是6小時。任何想法爲什麼?使用currentTimeMillis並關閉6個小時
public static void dateAndTime() {
Calendar cal = Calendar.getInstance();
int month = cal.get(Calendar.MONTH)+1;
int day = cal.get(Calendar.DATE);
int year = cal.get(Calendar.YEAR);
long totalMilliseconds = System.currentTimeMillis();
long totalSeconds = totalMilliseconds/1000;
int currentSecond = (int)(totalSeconds % 60);
long totalMinutes = totalSeconds/60;
int currentMinute = (int)(totalMinutes % 60);
long totalHours = totalMinutes/60;
int currentHour = (int)(totalHours % 24);
System.out.println (year + "-" + month + "-" + day + " " + currentHour + ":" + currentMinute + ":" + currentSecond);
}