- //比较两个字符串日期相差的天数
- //1秒=1000毫秒
- public int compDate(String bigDate,String smallDate){ int day = 0;
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
- try {
- //将"yyyy-mm-dd"字符串格式的日期转换为java.util.Date型
- Date bigDay = sdf.parse(bigDate);
- Date smallDay = sdf.parse(smallDate);
- day = (int)((bigDay.getTime()-smallDay.getTime())/3600/24/1000);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- return day;
- }
转载于:https://blog.51cto.com/3376739/859839