java - How do I convert seconds into accumulated hhh:mm:ss? -
i want convert elapsed amount of accumulated seconds hours:minutes:seconds. example
93599 seconds to:
25:59:59
how can that? (note: 24h should not wrap 0h)
the modulus operator %
useful here. work well
public static void converttime(int seconds) { int secs = seconds % 60; int mins = (seconds / 60) % 60; int hours = (seconds / 60) / 60; system.out.printf("%d:%d:%d", hours, mins, secs); }
Comments
Post a Comment