lannyf
lannyf

Reputation: 11035

Android, get wrong Date convert from GregorianCalendar.getTime()

GregorianCalendar gd1 = new GregorianCalendar(2013,12,12);

Date d = gd1.getTime();

Sun Jan 12 00:00:00 EST 2014  <===== what's wrong?

Is there a simpler way to construct Date for certain date (the Date(year, month, day) is deprecated). Thanks!

Upvotes: 1

Views: 1211

Answers (1)

Jumbala
Jumbala

Reputation: 4944

The GregorianCalendar class' months are zero-based (many people see this as a mistake, but that's not the point).

If you actually want to put the date as December 12, 2013, you would have to use the following line:

GregorianCalendar gd1 = new GregorianCalendar(2013,11,12);

Upvotes: 3

Related Questions