• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using System.currentTimeMillis() method

 
Roger Fed
Ranch Hand
Posts: 82
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Time zone difference?
 
Ernie Mcracken
Ranch Hand
Posts: 33
Mac Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works fine for me..

Time:21:18:55
 
Rob Spoor
Sheriff
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Roger Fed
Ranch Hand
Posts: 82
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much for helping me
 
Rob Spoor
Sheriff
Pie
Posts: 20659
64
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50168
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic