2013-10-31 4 views
0

2:25 PM에 안드로이드 Google 캘린더에 알람을 생성했습니다. 그런 다음 이벤트 알람 의도를 캡처하려고 시도했지만 알람 시간을 포맷하면 다른 시간이 표시됩니다. 여기Google 캘린더의 알림 시간

내가

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

당신이 차이가있는 이유를 알아 내 시간 포맷이를 사용하여 내 로그

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! 

입니까?

편집 : 포맷되지 않은 시간

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이 월을 저장하는 방법에 있습니다. 0Calendar.JANUARY으로 시작하므로 형식이없는 달은 "실제 달"보다 1 덜 표시됩니다.

12 시간 대 24 시간의 경우 SimpleDateFormat에서 hh 대신 24 시간 동안 HH을 사용하십시오.

+0

답변을 주셔서 감사합니다. 이유를 찾았습니다. 15 분 미리 알림을 설정하면 실제 알람이 15 분 후에 발생하더라도 해당 알람 시간과 시작 시간이 표시됩니다. – jantox

+1

아, 알겠습니다. 예, 알람은 실제 이벤트 시간이 아닌 미리 알림을 기반으로 설정됩니다. 이벤트 시간에 알람을 받으려면 알림을 0 분으로 설정하십시오. :) –

관련 문제