Win a copy of Machine Learning with TensorFlow this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

Difficulties while converting from long to time format

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you post an SSCCE?
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Marshal
Posts: 26388
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic