0

Android の Google カレンダーで午後 2 時 25 分にアラームを作成しました。そして、イベントアラームの意図をキャプチャしようとしましたが、アラーム時刻をフォーマットすると、別の時刻が表示されます。

ここに私のログがあります

  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);
4

1 に答える 1

0

あなたのに問題はありませんSimpleDateFormat。問題はCalendar、月の格納方法にあります。0asで始まるCalendar.JANUARYため、フォーマットされていない月は「実際の月」より 1 少なく表示されます。

12 時間対 24 時間HHについてhhは、SimpleDateFormat.

于 2013-10-31T06:43:02.843 に答える