| Author |
Using System.currentTimeMillis() method
|
Roger Fed
Ranch Hand
Joined: Oct 17, 2010
Posts: 82
|
|
hello
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
Marshal
Joined: Jan 10, 2002
Posts: 56185
|
|
Time zone difference?
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Ernie Mcracken
Ranch Hand
Joined: Feb 13, 2011
Posts: 33
|
|
Works fine for me..
Time:21:18:55
|
You're on a gravy train with biscuit wheels Roy.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
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:
|
SCJP 1.4 - SCJP 6 - SCWCD 5
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
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
You're welcome.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
|
|
|
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.
|
 |
 |
|
|
subject: Using System.currentTimeMillis() method
|
|
|