This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Zero to AI - A non-technical, hype-free guide to prospering in the AI era and have Nicolò Valigi and Gianluca Mauro on-line!
See this thread for details.
Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning 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
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

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: 8943
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: 8943
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: 8943
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: 8943
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: 8943
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic