aspose file tools*
The moose likes Beginning Java and the fly likes Date 01/01/1970 returning non-zero value for time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date 01/01/1970 returning non-zero value for time" Watch "Date 01/01/1970 returning non-zero value for time" New topic
Author

Date 01/01/1970 returning non-zero value for time

Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211



The resulting output is


Hi Everyone,

What am I missing here, why is the date created returning a negative value for getTime()? Shouldnt it be 0?

Sonny
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
getTime
public long getTime()Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.

Returns:
the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date.


But in your code is wrong to define year.


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.


I think it is negative because it is MYT and not GMT time zone.


Groovy
Peter van der Linden
author
Ranch Hand

Joined: Sep 28, 2004
Posts: 46
What timezone are you in, Sonny?

Are you by any chance in a time zone which is 27,000 seconds earlier than Greenwich?

27,000 seconds = 7.5 hours.
That would be (approx 15 degrees for each hour), equals 112.5 degrees east of Greenwich.

Cheers,

Peter


Author of <a href="http://www.amazon.com/exec/obidos/ASIN/0131482114/ref=jranch-20" target="_blank" rel="nofollow">Just Java(TM) 2 (6th Edition)</a>
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

I got the following output. My timezone is +5.30 GMT.


Thu Jan 01 00:00:00 GMT+05:30 1970
-19800000
Thu Jan 01 00:00:00 GMT+05:30 1970
-19800000
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
I'm test your code in my computer with change TimeZone in "GMT" , it work fine.




Result


[ September 28, 2004: Message edited by: somkiat puisungnoen ]
[ September 28, 2004: Message edited by: somkiat puisungnoen ]
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

MYT is Malaysia time.
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Originally posted by Pradeep Bhat:
I got the following output. My timezone is +5.30 GMT.



you got negative number because current timezone in your computer is fast than GMT (Standard timezone for java)
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

To find out the GMT time for your date object add the following line

System.out.println(date.toGMTString());

This will tell you why it is not zero.
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Right on the mark Peter, and Pradeep.I am in Malaysia.
Time to go back and read up on the Javadocs for Date related classes again.

Thanks a lot, guys.
Sonny
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
Originally posted by Pradeep Bhat:
To find out the GMT time for your date object add the following line

System.out.println(date.toGMTString());

This will tell you why it is not zero.


toGMTString() method of java.util.Date is depricated.

Deprecated. As of JDK version 1.1, replaced by DateFormat.format(Date date), using a GMT TimeZone.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Originally posted by somkiat puisungnoen:
[QB][/QB]



Yes I know it is deprecated but I hope you got my message.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Date 01/01/1970 returning non-zero value for time