A question about Date()

Posted on 2006-05-11
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
    LVL 33

    Expert Comment

    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

    I would recommend you using the GregorianCalendar instead of the deprecated Date

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

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    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…
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now