我想在用户设置的某个日期开始闹钟。问题是警报应该开始的时间会产生非常混乱的值。以下是设置时间的方法等。字符串taskDate
是用户选择的日期,类似5-12-2011
:
private void startAlarm(String taskDate)
{
AlarmManager alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
String [] taskDateArray = taskDate.split("-");
int day = Integer.parseInt(taskDateArray[0].trim());
int month = Integer.parseInt(taskDateArray[1].trim());
int year = Integer.parseInt(taskDateArray[2].trim());
Log.w(TAG, "Year " + year + " Month " + month + " Day " + day);
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1); // Month is zero-based
calendar.set(Calendar.DAY_OF_MONTH, day);
long alarmTime = calendar.getTimeInMillis();
Intent intent = new Intent(this, RememberMeService.class);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, 0);
alarmManager.set(AlarmManager.RTC, alarmTime, pendingIntent);
}
alarmTime
的价值总是超过30亿,我不明白为什么。