This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Date class related query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Date class related query" Watch "Date class related query" New topic

Date class related query

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1067 || OCJP:81%
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

java.util.Date holds the date as the number of milliseconds since the epoch of 1/1/1970 00:00:00 UTC. The constructor you are using is using the value you provide as this millisecond value so '2' means 1/1/1970 00:00:02 UTC. The toString() method uses your current time zone when converting the milliseconds to a String.

Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Mohamed El-Feky

Joined: Jan 14, 2011
Posts: 19

absolutely right

you might try to use different constructor to get diff response

Learn it, Live it, Love it
Java is my passion
Rob Spoor

Joined: Oct 27, 2005
Posts: 20049

Almost right. Not 1/1/1970 00:00:02 UTC but 1/1/1970 00:00:00.002 UTC.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Date class related query
It's not a secret anymore!