码迷,mamicode.com
首页 > 其他好文 > 详细

Date日期比对

时间:2014-09-17 14:59:22      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   ar   div   sp   log   on   c   

 1      Calendar calendar1 = Calendar.getInstance();
 2         Calendar calendar2 = Calendar.getInstance();
 3         calendar1.set(2007, 01, 10);
 4         calendar2.set(2008, 07, 01);
 5         long milliseconds1 = calendar1.getTimeInMillis();
 6         long milliseconds2 = calendar2.getTimeInMillis();
 7         long diff = milliseconds2 - milliseconds1;
 8         long diffSeconds = diff / 1000;
 9         long diffMinutes = diff / (60 * 1000);
10         long diffHours = diff / (60 * 60 * 1000);
11         long diffDays = diff / (24 * 60 * 60 * 1000);
12         System.out.println("\nThe Date Different Example");
13         System.out.println("Time in milliseconds: " + diff + " milliseconds.");
14         System.out.println("Time in 秒: " + diffSeconds + " seconds.");
15         System.out.println("Time in 分钟: " + diffMinutes + " minutes.");
16         System.out.println("Time in 小时: " + diffHours + " hours.");
17         System.out.println("Time in 天: " + diffDays + " days.");

 

Date日期比对

标签:style   blog   color   ar   div   sp   log   on   c   

原文地址:http://www.cnblogs.com/duwenlei/p/3977010.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!