其他分享
首页 > 其他分享> > 计算两个日期的月份

计算两个日期的月份

作者:互联网

public static Integer getDifMonth(Date startDate, Date endDate){
        Calendar start = Calendar.getInstance();
        Calendar end = Calendar.getInstance();
        start.setTime(startDate);
        end.setTime(endDate);
        int result = end.get(Calendar.MONTH) - start.get(Calendar.MONTH);
        int month = (end.get(Calendar.YEAR) - start.get(Calendar.YEAR)) * 12;
        return Math.abs(month + result);
    }

 

标签:startDate,end,月份,get,start,日期,计算,endDate,Calendar
来源: https://www.cnblogs.com/zhaojiu/p/15118896.html