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);
        }
  • 相关阅读:
    POJ
    FZU
    HDU
    HDU
    HDU
    HDU
    Educational Codeforces Round 84 E. Count The Blocks
    B Boundary(由弦求圆)
    D. Maximum Sum on Even Positions(翻转1次,求最大偶数位和)
    E. DeadLee(思维,拓扑图处理)
  • 原文地址:https://www.cnblogs.com/qingyibusi/p/10560308.html
Copyright © 2011-2022 走看看