code_junkie

How to convert milliseconds into human readable form?

Nov 11th, 2011
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. x = ms / 1000
  2. seconds = x % 60
  3. x /= 60
  4. minutes = x % 60
  5. x /= 60
  6. hours = x % 24
  7. x /= 24
  8. days = x
  9.  
  10. seconds=(A/1000)%60
  11. minutes=(A/(1000*60))%60
  12. hours=(A/(1000*60*60))%24
  13.  
  14. int milliseconds = someNumber;
  15.  
  16. int seconds = milliseconds / 1000;
  17.  
  18. int minutes = seconds / 60;
  19.  
  20. seconds %= 60;
  21.  
  22. int hours = minutes / 60;
  23.  
  24. minutes %= 60;
  25.  
  26. int days = hours / 24;
  27.  
  28. hours %= 24;
  29.  
  30. Long serverUptimeSeconds =
  31. (System.currentTimeMillis() - SINCE_TIME_IN_MILLISECONDS) / 1000;
  32.  
  33.  
  34. String serverUptimeText =
  35. String.format("%d days %d hours %d minutes %d seconds",
  36. serverUptimeSeconds / 86400,
  37. ( serverUptimeSeconds % 86400) / 3600 ,
  38. ((serverUptimeSeconds % 86400) % 3600 ) / 60,
  39. ((serverUptimeSeconds % 86400) % 3600 ) % 60
  40. );
Add Comment
Please, Sign In to add comment