vein
vein

Reputation: 315

Set Alarm by Calendar-Object

I want to start a alarm at a certain date which is set by the user. The problem is that the time in which the alarm should start takes a very confusing value. Here's the method in which the time is set etc. The String taskDate is the date which is choosen by the user which is something like 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);
}

The value of alarmTime is always more than three billion and I have no idea why.

Upvotes: 1

Views: 431

Answers (1)

Ramseys
Ramseys

Reputation: 431

It is the internal representation of a date, that is

number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

as stated in date Javadoc

Upvotes: 1

Related Questions