Posted on 2006-01-06 11:56
Eddie Lee 阅读(1244)
评论(0) 编辑 收藏
1 /*计算两个任意日期间的相差的天数(自然天) */
2
3 public int computeCoolingOffPeriod(String sBeginDate,String sEndDate) throws Exception{
4 Calendar calendar1=Calendar.getInstance();;
5 Calendar calendar2=Calendar.getInstance();;
6 SimpleDateFormat formatter1 = new SimpleDateFormat("yyyyMMdd");//格式很重要:是20051031,还是2005-10-31格式呢?
7 if (sBeginDate.equals("0")) {System.out.println("sBirthDate.equals====0"); sBeginDate = "19000101"; }
8
9 calendar1.setTime(formatter1.parse(sBeginDate));
10 calendar2.setTime(formatter1.parse(sEndDate));
11
12 return (int)( (calendar2.getTimeInMillis()-calendar1.getTimeInMillis())/1000/60/60/24 );//获取天数的差值。
13
14
15 }
16