0
点赞
收藏
分享

微信扫一扫

(转)How to convert milliseconds into human readable form?

小月亮06 2022-08-04 阅读 54


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://stackoverflow.com/questions/175554/how-to-convert-milliseconds-into-human-readable-form

举报

相关推荐

0 条评论