1 /** 2 * <li>功能描述:时间相减得到天数 3 * @param beginDateStr 4 * @param endDateStr 5 * @return 6 * long 7 * @author Administrator 8 */ 9 public static long getDaySub(String beginDateStr,String endDateStr) 10 { 11 long day=0; 12 java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("yyyy-MM-dd"); 13 java.util.Date beginDate; 14 java.util.Date endDate; 15 try 16 { 17 beginDate = format.parse(beginDateStr); 18 endDate= format.parse(endDateStr); 19 day=(endDate.getTime()-beginDate.getTime())/(24*60*60*1000); 20 //System.out.println("相隔的天数="+day); 21 } catch (ParseException e) 22 { 23 // TODO 自动生成 catch 块 24 e.printStackTrace(); 25 } 26 return day; 27 }
来源:http://blog.163.com/xiaomi_8266/blog/static/72076427201092814636812/