2013-10-31 35 views
0

我在下午2:25在android Google Calendar中創建了一個鬧鐘。然後我嘗試捕獲事件鬧鐘的意圖,但是當我格式化鬧鐘時間時,它顯示的是不同的時間。Google日曆中的通知時間

這是我的日誌

10-31 14:25:18.475: D/@@@@@ Notify(25637): event name: New event 
    10-31 14:25:18.475: D/@@@@@ Notify(25637): alarm time formatted: 2013-10-31 02:11 
    10-31 14:25:18.475: D/@@@@@ Notify(25637): alarm time not formatted: 2013-9-31 2:11 
    10-31 14:25:18.475: D/@@@@@ Notify(25637): today: 2013-9-31 14:25 
    10-31 14:25:18.475: D/@@@@@ Notify(25637): today formatted: 2013-10-31 02:25 
    10-31 14:25:18.480: I/CalendarTest(25637): CalendarTest.onReceive called! 

我用這個來格式化我的時間

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm"); 

你知道爲什麼有差異?

編輯:格式化時間

Date dtAlarmTime = new Date(alarmTime); 
Calendar alarm_cal = Calendar.getInstance(); 
alarm_cal.setTime(dtAlarmTime); 

int alarm_year = alarm_cal.get(Calendar.YEAR); 
int alarm_month = alarm_cal.get(Calendar.MONTH); 
int alarm_day = alarm_cal.get(Calendar.DAY_OF_MONTH); 
int alarm_hour = alarm_cal.get(Calendar.HOUR); 
int alarm_minute = alarm_cal.get(Calendar.MINUTE); 
+0

如何打印非格式化日期? –

回答

0

沒有什麼不對您的SimpleDateFormat。問題在於Calendar如何存儲月份。它從0開始爲Calendar.JANUARY,所以您的非格式化月份將顯示爲比「真實月份」少1個月。

至於12小時和24小時,使用HH爲24小時,而不是在SimpleDateFormathh

+0

感謝您的答案,我想我找到了原因。 當我設置15分鐘提醒時,即使真正的鬧鐘應該在15分鐘後,它也會獲得鬧鐘時間和開始時間。 – jantox

+1

啊,我明白了。是的,警報是根據提醒設置的,而不是真實的事件時間。如果您想在活動時間發出警報,請將提醒設置爲0分鐘:) –