使用 DurationFormatUtils 计算时间间隔

来源:互联网 发布:如何学好高中化学知乎 编辑:程序博客网 时间:2024/05/22 09:02
  // 当前时间  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(), "yyyy-MM-dd HH:mm:ss"));  System.out.println(DurationFormatUtils.formatDuration(expo2010BeginDate.getTime() - expo2010EndDate.getTime(),    "yyyy-MM-dd HH:mm:ss"));



1 0
原创粉丝点击