zoukankan      html  css  js  c++  java
  • 日期计算

    相差天数:

        public static int getDayDiff(Date startTime, Date endTime){
            return (int) ((endTime.getTime() + 28800000) / 86400000 - (startTime.getTime() + 28800000) / 86400000);
        }

    相差周数:

        public static int getWeekDiff(Date startTime, Date endTime){
            return (int) ((endTime.getTime() + 288000000) / 604800000 - (startTime.getTime() + 288000000) / 604800000);
        }

    相差月数:

        public static int getMonthDiff(Date startTime, Date endTime) {
            Calendar start = Calendar.getInstance();
            Calendar end = Calendar.getInstance();
            start.setTime(startTime);
            end.setTime(endTime);
            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);
        }
  • 相关阅读:
    C++课程的第一次实验
    First C++
    7-12 关于堆的判断
    大笨钟
    7-14 喊山
    L3-010 是否完全二叉搜索树 (30分)
    7-13 天梯地图
    7-10 排座位
    7-9 抢红包
    帅到没朋友
  • 原文地址:https://www.cnblogs.com/qingyibusi/p/10560308.html
Copyright © 2011-2022 走看看