• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Sonny Gill
Ranch Hand
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter van der Linden
author
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
MYT is Malaysia time.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1211
IntelliJ IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by somkiat puisungnoen:
[QB][/QB]



Yes I know it is deprecated but I hope you got my message.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic