This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Using System.currentTimeMillis() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using System.currentTimeMillis() method" Watch "Using System.currentTimeMillis() method" New topic

Using System.currentTimeMillis() method

Roger Fed
Ranch Hand

Joined: Oct 17, 2010
Posts: 82

I've developed this time class
A no-arg constructor that creates a Time object for the current time. (The data fields value will represent the current time)
when running the program it display the hour data field decreased by 2 hours
is there any reason for this??
thanks in advance

this is the Time class

I Hear I Forget, I See I Remember, I Do I Understand.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63232

Time zone difference?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ernie Mcracken
Ranch Hand

Joined: Feb 13, 2011
Posts: 33

Works fine for me..


You're on a gravy train with biscuit wheels Roy.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20083

One hour off here, and the reason is probably quite simple: daylight savings time. Your code assumes that each and every day since the epoch, January 1st 1970 at 0:00:00, is 24 hours. That assumption is wrong; there are days with 23 hours and days with 25 hours.

If you need this Time class you probably want to use java.util.Calendar to calculate the current values:

How To Ask Questions How To Answer Questions
Roger Fed
Ranch Hand

Joined: Oct 17, 2010
Posts: 82

Thanks very much for helping me
Rob Spoor

Joined: Oct 27, 2005
Posts: 20083

You're welcome.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 44048
Even worse, the "epoch" was in GMT, but we had summer time all winter here in Britain in 1970, so the clocks all showed 1.00am then.
Have you checked out Aspose?
subject: Using System.currentTimeMillis() method
It's not a secret anymore!