您的位置:首页 > 其它

使用 DurationFormatUtils 计算时间间隔

2012-03-09 00:00 113 查看
// 当前时间
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参数

characterduration element
yyears
Mmonths
ddays
Hhours
mminutes
sseconds
Smilliseconds
$(document).ready(function(){dp.SyntaxHighlighter.HighlightAll('code');});

原文链接:
http://blog.csdn.net/kimsoft/article/details/5106984
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: