• Post Reply Bookmark Topic Watch Topic
  • New Topic

Difficulties while converting from long to time format  RSS feed

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I am reading time values from the DB for the fields from time and to time. However, I need to calculate the difference between them, So, I decided to convert the time to long and do the difference.

But, when I am trying again to get the value in the Time format HH:MM:SS, I am finding diffuclties that the result is not correct.



The actual result is 6:00:00.
Can you please help in solving this issue
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post an SSCCE?
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I assume that part of your problem is that the "HH:MM:SS" should be "HH:mm:ss". MM:SS are month/millseconds. However when I run it everything is an hour more than it should be, which means that 21600000=07:00:00. If you get the same result I guess you can reduce all long times by 3600000(1 hour in milli).
 
Sheriff
Posts: 22846
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The timestamp you are generating from that long is an offset starting at midnight January 1, 1970, in GMT. Presumably your computer's time zone is not GMT, so the time formatting is making an adjustment of a certain number of hours.

You don't want that adjustment, so set the time zone of the SimpleDateFormat to be GMT.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!