0
如何在倒計時上設置我的時差?如何倒數計時器
我有我的java代碼的時間差,我想要做的就是倒計時。
這是我的java代碼。
public class time {
public void printDifference(Date endDate){
Date now = new Date();
Date startDate = now;
//milliseconds
long different = endDate.getTime() - startDate.getTime();
System.out.println("startDate : " + startDate);
System.out.println("endDate : "+ endDate);
System.out.println("different : " + different);
long secondsInMilli = 1000;
long minutesInMilli = secondsInMilli * 60;
long hoursInMilli = minutesInMilli * 60;
long daysInMilli = hoursInMilli * 24;
long elapsedDays = different/daysInMilli;
different = different % daysInMilli;
long elapsedHours = different/hoursInMilli;
different = different % hoursInMilli;
long elapsedMinutes = different/minutesInMilli;
different = different % minutesInMilli;
long elapsedSeconds = different/secondsInMilli;
System.out.printf(
"%d days, %d hours, %d minutes, %d seconds%n",
elapsedDays,
elapsedHours, elapsedMinutes, elapsedSeconds);
}
public static void main(String[] args) {
}
}
歡迎堆棧溢出!請查看我們的[SO問題清單](http://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist)來幫助你提出一個好問題,從而得到一個很好的答案。 –