code_junkie

How to format a duration in java? (e.g format H:MM:SS)

Nov 12th, 2011
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.27 KB | None | 0 0
  1. String.format("%d:%02d:%02d", s/3600, (s%3600)/60, (s%60))
  2.  
  3. long duration = 4 * 60 * 60 * 1000;
  4. SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS", Locale.getDefault());
  5. log.info("Duration: " + sdf.format(new Date(duration - TimeZone.getDefault().getRawOffset())));
Add Comment
Please, Sign In to add comment