This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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

 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • 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
 
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.
 
Ranch Hand
Posts: 8934
Firefox Browser Spring Java
  • 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.
 
author
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: 8934
Firefox Browser Spring Java
  • 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: 8934
Firefox Browser Spring Java
  • 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: 8934
Firefox Browser Spring Java
  • 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
Mac IntelliJ IDE
  • 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: 8934
Firefox Browser Spring Java
  • 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.
 
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!