我有一个函数可以输出 yyyy/mm/dd hh:mm:ss。一切都非常准确,除了小时,它似乎提前了 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);
}