jQuery in Action, 2nd edition
The moose likes Beginning Java and the fly likes Using System.currentTimeMillis() method Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Using System.currentTimeMillis() method" Watch "Using System.currentTimeMillis() method" New topic
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
    
  13

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
    
    4
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Using System.currentTimeMillis() method
 
Similar Threads
Explanation o f concatenated method calls/cascaded method calls
I need help refining some code
Reassign
classes and methods
I would like to have your advice about the way I have designed the application