Date and DateFormat question - newbie

S

Sting

Hello,

I have the follwing test:

static void test()
{
Date today = new Date();
Date date = new Date(30000000);

DateFormat dateFormatter;
Locale currentLocale = new Locale("en","US");

dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT,
currentLocale);

String dateOut = dateFormatter.format(date);
String todayOut = dateFormatter.format(today);

System.out.println("todayOut" + todayOut);
System.out.println("todayOut toString:" + todayOut.toString());

System.out.println("****************************");

System.out.println("dateOut" + dateOut);
System.out.println("dateOut toString:" + dateOut.toString());

}

the output is:
todayOutFeb 19, 2004
todayOut toString:Feb 19, 2004
****************************
dateOutJan 1, 1970
dateOut toString:Jan 1, 1970

I do not understand the results of dateOut : why is it Jan 1, 1970 ?
It should have been somewhere in 1971 since I had passed
30000000 to the Date ctor ; which means 30000000 seconds from 1/1/70.
any help will be appreciated.
regards,
sting
 
S

Suresh

Sting said:
Hello,

I have the follwing test:

static void test()
{
Date today = new Date();
Date date = new Date(30000000);

Try Date date = new Date(30000000L);


[..snip..]
 
T

Thomas Weidenfeller

Sting said:
I do not understand the results of dateOut : why is it Jan 1, 1970 ?
It should have been somewhere in 1971 since I had passed
30000000 to the Date ctor ; which means 30000000 seconds from 1/1/70.

MILLIseconds - please read the API documentation.
30000000 milliseconds is less than 10 hours into 1970-01-01.

And please, consider posting newbie questions to comp.lang.java.help.

/Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top