0
在這裏意外的結果是代碼,爲您的觀賞樂趣:減去日期
public static void main(String[] args) throws Exception {
Calendar cal = Calendar.getInstance();
cal.set(2010, Calendar.JULY, 10, 1, 0, 20);
Date d1 = cal.getTime();
Date d2 = new Date();
int seconds = 22;
d2.setTime(d1.getTime() - seconds*1000);
SimpleDateFormat iso_format = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
System.out.println(iso_format.format(d1) + " - " + seconds + "s = " + iso_format.format(d2));
}
輸出:2010-07- 10點 1點零零分20秒 - 22 = 2010-07- 24 :59:58
答案不應該是2010-07- 24:59:58?爲什麼它會回到同一天?有沒有辦法解決它?
更好的問題:爲什麼它不是2010-07-10〇時59分58秒(之前22秒1點○○分二十秒) – DennyRolling 2010-11-08 02:12:04
@High:使用'k'格式說明時,小時字段∈'[1,24]'不''[0,23]'。 – 2010-11-08 02:22:05
爲什麼世界上任何人都想要一個∈[1,24]的小時格式說明符? – 2010-11-08 02:30:28