(转)How to convert milliseconds into human readable form?
程序员文章站
2022-04-30 11:29:15
...
x = ms / 1000 seconds = x % 60 x /= 60 minutes = x % 60 x /= 60 hours = x % 24 x /= 24 days = x
public static String formatMs(long millis) { long hours = TimeUnit.MILLISECONDS.toHours(millis); long mins = TimeUnit.MILLISECONDS.toMinutes(millis); long secs = TimeUnit.MILLISECONDS.toSeconds(millis); return String.format("%dh %d min, %d sec", hours, mins - TimeUnit.HOURS.toMinutes(hours), secs - TimeUnit.MINUTES.toSeconds(mins) ); }
转自:http://*.com/questions/175554/how-to-convert-milliseconds-into-human-readable-form
下一篇: 将毫秒 换算成(天 时 分 秒 毫秒)