A question about Date()

Posted on 2006-05-11
Medium Priority
Last Modified: 2010-03-31
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.

Question by:chenwei
  • 2
LVL 33

Expert Comment

ID: 16665178
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.
LVL 33

Accepted Solution

hongjun earned 80 total points
ID: 16665197
I would recommend you using the GregorianCalendar instead of the deprecated Date

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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question