Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

Problem about Date

Thread view: 
Sameer - 12 Sep 2006 06:52 GMT
Please watch the following code:
(Though the constructor Date(int year, int month, int date) was
deprecated)
Note that I am creating a date object for the date 1 July 2006.

import java.util.*;
import java.text.*;

//The date is represented as a Date object or
//as the milliseconds since January 1, 1970,00:00:00 GMT.
public class DateDemo1 {
public static void main(String args[]) throws ParseException {
Date date= new Date(2006,7,1);
System.out.println("String representation of current
date:"+date.toString());
}
}

The output is
String representation of current date:Wed Aug 01 00:00:00 IST 3906

Am I wrong? What may be the problem?
How to create Date instance for desired date?
Andrew Thompson - 12 Sep 2006 07:10 GMT
> Please watch the following code:
> (Though the constructor Date(int year, int month, int date) was
> deprecated)
> Note that I am creating a date object for the date 1 July 2006.
...
> The output is
> String representation of current date:Wed Aug 01 00:00:00 IST 3906
>
> Am I wrong?

Yes.  Note the instructions in the documentation for the
"three ints" form of the constructor.
<http://java.sun.com/j2se/1.5.0/docs/api/java/util/Date.html#Date(int,%20int,%20int)>

>...What may be the problem?

Note also, that constructor is deprecated.

> How to create Date instance for desired date?

Try reading the rest of that document.

Andrew T.
Andrew Thompson - 12 Sep 2006 07:12 GMT
> > Please watch the following code:
> > (Though the constructor Date(int year, int month, int date) was
> > deprecated)
....
> Note also, that constructor is deprecated.

Oh.   ....Ooops!
Arne Vajhøj - 12 Sep 2006 22:16 GMT
>> The output is
>> String representation of current date:Wed Aug 01 00:00:00 IST 3906
[quoted text clipped - 4 lines]
> "three ints" form of the constructor.
> <http://java.sun.com/j2se/1.5.0/docs/api/java/util/Date.html#Date(int,%20int,%20int)>

Specifically:

year - the year minus 1900.

(2006+1900=3906)

Arne


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.