A question about Date()

My code looks as follow:

  Date myBirthday = new Date(2003, 4, 12);

But to my strange I got "Tue May 12 08:29:18 CEST 3903". Man cab see the month and the year are not what I've given.

Who is Participating?
I would recommend you using the GregorianCalendar instead of the deprecated Date

GregorianCalendar myBirthday = new GregorianCalendar(2003, 4, 12);
You need to minu 1900 for the year.
As for the year, you Jan is 0, Feb is 1, and so on.

So, for Apr, you need to pass in 3 instead of 4.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.