使用 DurationFormatUtils 计算时间间隔
2016-04-27 10:38
851 查看
原文地址:http://blog.csdn.net/kimsoft/article/details/5106984
// 当前时间
Date now = new Date();
// 2010上海世博会开幕时间
Date expo2010BeginDate = DateUtils.parseDate("2010-05-01 23:59:59", new String[] { "yyyy-MM-dd HH:mm:ss" });
// 2010上海世博会闭幕时间
Date expo2010EndDate = DateUtils.parseDate("2010-10-31 23:59:59", new String[] { "yyyy-MM-dd HH:mm:ss" });
System.out.println(DurationFormatUtils.formatDuration(expo2010BeginDate.getTime() - now.getTime(), "d"));
System.out.println(DurationFormatUtils.formatDuration(expo2010BeginDate.getTime() - expo2010EndDate.getTime(),
"d"));
Duration formatting utilities and constants. The following table describes the tokens used in the pattern language for formatting.
以下是format参数
// 当前时间
Date now = new Date();
// 2010上海世博会开幕时间
Date expo2010BeginDate = DateUtils.parseDate("2010-05-01 23:59:59", new String[] { "yyyy-MM-dd HH:mm:ss" });
// 2010上海世博会闭幕时间
Date expo2010EndDate = DateUtils.parseDate("2010-10-31 23:59:59", new String[] { "yyyy-MM-dd HH:mm:ss" });
System.out.println(DurationFormatUtils.formatDuration(expo2010BeginDate.getTime() - now.getTime(), "d"));
System.out.println(DurationFormatUtils.formatDuration(expo2010BeginDate.getTime() - expo2010EndDate.getTime(),
"d"));
Duration formatting utilities and constants. The following table describes the tokens used in the pattern language for formatting.
以下是format参数
character | duration element |
---|---|
y | years |
M | months |
d | days |
H | hours |
m | minutes |
s | seconds |
S | milliseconds |
相关文章推荐
- itext使用模板生成pdf文件
- CSS实现水平居中的5种思路
- 5_6 团体队列(UVa540)<queue与STL其他容器的综合运用>
- spring 配置触发器 (类似于定时任务)
- 有三个线程T1 T2 T3,如何保证他们按顺序执行-转载
- 黑幕背后的__block修饰符
- 面向结构化编程与面向对象编程
- bootstrap模版
- 溢出判断
- c++使用rapidxml
- 手动/自动选网
- easyui和highcharts 动态加载数据和X轴数据
- 【Android进阶学习】shape和selector的结合使用(转)
- 刨根问底Objective-C Runtime(4)- 成员变量与属性
- Masonry介绍与使用实践(快速上手Autolayout)
- 刨根问底Objective-C Runtime(3)- 消息 和 Category
- 数据结构与算法习题汇总(4)
- java中的缓存技术该如何实现
- 【总结】CSS/CSS3常用样式小结——兼容性
- what the hell it is?!