- 求两个时间相差月份
SimpleDateFormat yyyyMM = new SimpleDateFormat("yyyyMM");
Calendar cal1 = Calendar.getInstance();
cal1.setTime(yyyyMM.parse(startTime));
Calendar cal2 = Calendar.getInstance();
cal2.setTime(yyyyMM.parse(endTime));
return (cal2.get(Calendar.YEAR) - cal1
.get(Calendar.YEAR))* 12+ cal2.get(Calendar.MONTH)
- cal1.get(Calendar.MONTH);
本文介绍了一种使用Java计算两个日期之间相差月份的方法。通过SimpleDateFormat和Calendar类,可以准确地获取到两个时间点之间的月份数差异。
3799

被折叠的 条评论
为什么被折叠?



