File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 60765

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: 19651

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: 19651

You're welcome.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 37936
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:
subject: Using System.currentTimeMillis() method
Similar Threads
I need help refining some code
I would like to have your advice about the way I have designed the application
Explanation o f concatenated method calls/cascaded method calls
classes and methods