File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Beginning Java
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: 61413
    
  67

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..

Time:21:18:55


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

Joined: Oct 27, 2005
Posts: 19718
    
  20

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 - OCEEJBD 6
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: 19718
    
  20

You're welcome.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39386
    
  28
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://aspose.com/file-tools
 
subject: Using System.currentTimeMillis() method