Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting millisecs to hour, minute, seconds.

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an interval of time in milliseconds.
Is there any utility to convert that
to an interval specified in
hour:minute:sec
Thanks
Pho
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can use a combination of the java.util.Calendar and java.util.Date
Check out these methods in particular:
void Date.setTime(long time);
and
Date Calendar.getTime();
 
Bob Smith
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just divide by 1000, 60 etc.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hours = ms / (1000*60*60);
ms = ms % (1000*60*60);
minutes = ms / (1000*60);
ms = ms % (1000*60);
seconds = ms / 1000;
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all.
Pho.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic