求两个时间差的天数、小时、分钟、秒
2015-12-17 12:29
323 查看
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date d1 = null; Date d2 = null; try { d1 = format.parse(dateStart); d2 = format.parse(dateStop); //毫秒ms long diff = d2.getTime() - d1.getTime(); long diffSeconds = diff / 1000 % 60; long diffMinutes = diff / (60 * 1000) % 60; long diffHours = diff / (60 * 60 * 1000) % 24; long diffDays = diff / (24 * 60 * 60 * 1000); System.out.print("两个时间相差:"); System.out.print(diffDays + " 天, "); System.out.print(diffHours + " 小时, "); System.out.print(diffMinutes + " 分钟, "); System.out.print(diffSeconds + " 秒."); } catch (Exception e) { e.printStackTrace(); }
相关文章推荐
- 托盘图标的制作,点击与触发
- 轻量级JavaEE企业应用实战(六)
- 95,autorelease的注意事项
- No important thing
- iOS工作小常识
- iOS 【UIKit-iOS事件之触摸事件】
- retain、copy、mutableCopy的区别(深拷贝 浅拷贝)
- 如何获取选中的复选框
- Java 斐波那契数列
- 第一次了解GitHub,在Windows下使用GitHub
- 深入理解Java的接口和抽象类(转载---写的非常好~)
- sendmsg() Permission denied
- [网络管理]共享文件之卷影副本的使用
- Spring数据源配置总结
- python科学计算库安装
- python科学计算库安装
- python科学计算库安装
- python科学计算库安装
- python科学计算库安装
- python科学计算库安装