您的位置:首页 > 其它

毫秒数时间差转换为时分秒

2016-05-15 20:13 621 查看
原文链接:https://www.geek-share.com/detail/2674241644.html

毫秒数时间差转换为时分秒

思路:定一个毫秒数时间基点(当前时间点的毫秒数)。在时间基点上加上毫秒数时间差,定义为另一个时间点。把两个时间点转换为joda的时间点,使用joda计算时间差。

//相差的毫秒数
long difference = 1000*60*60 + 1000*60 + 1000;
//取基准点
long base = System.currentTimeMillis();

DateTime start = new DateTime(base);
DateTime end = new DateTime(base +  difference);

Interval interval = new Interval(start, end);
Period period = interval.toPeriod();

System.out.println(String.format("相差%d小时%d分钟%d秒",period.getHours(),period.getMinutes(),period.getSeconds()));

转载于:https://www.geek-share.com/detail/2674241644.html

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: