Reputation: 539
I'm a little confused of the handling between the java Date Class and GregorianCalendar in Android (2.1). In this example, the year, month, day, hour, minute values are coming from Date and Time pickers.
Date date = new Date(year, month, day, hour, minute);
GregorianCalendar senddate = new GregorianCalendar(year, month, day, hour, minute);
Log.v(LOG_TAG, senddate.getTimeInMillis() + "");
Log.v(LOG_TAG, date.getTime() + "");
output from the logging:
1297604340000
61255744740000
why is the date object so far off. what did i miss?
edit:
I ran my sample code again.
1297609440000
61255749840000
2011 - 1 - 13 - 16 - 4 (year - month - dayofmonth - hour - minute)
getting the values from:
int month = dpDate.getMonth();
int day = dpDate.getDayOfMonth();
int year = dpDate.getYear();
int hour = dpTime.getCurrentHour();
int minute = dpTime.getCurrentMinute();
Upvotes: 0
Views: 1985
Reputation: 15029
Possibly the cause is the difference in the construction API, to be precise, the year
field. For Date
class the year
field is the year minus 1900, where as for GregorianCalendar
it's the actual year.
Upvotes: 1