计算两个日期相隔月份
/** * * 比较日期月份 * @param start 开始日期 * @param end 结束日期 * @return Integer */ public static Integer diffMonth(Date start, Date end) { if (start == null || end == null) { return null; } Calendar cStart = Calendar.getInstance(); cStart.setTime(start); Calendar cEnd = Calendar.getInstance(); cEnd.setTime(end); int month = cEnd.get(Calendar.MONTH) - cStart.get(Calendar.MONTH); int year = cEnd.get(Calendar.YEAR) - cStart.get(Calendar.YEAR); return year * 12 + month; }
posted on 2021-09-14 17:17 lovezj9012 阅读(149) 评论(0) 编辑 收藏 举报