zoukankan      html  css  js  c++  java
  • 计算两个日期相隔的天数(jodd)

    public static void main(String[] args) throws ParseException {
            System.out.println(TimeUtil.dayOfYear(1992, 12, 31));
            System.out.println(TimeUtil.dayOfYear(2016, 3, 14));
            
            JDateTime time = new JDateTime(new Date());
            JDateTime time2 = new JDateTime(new SimpleDateFormat("yyyyMMdd").parse("20160310"));
            
            System.out.println(time2.daysBetween(time));
    }
    daysBetween源码分析
    /**
         * Calculates the number of days between two dates. Returned value is always positive.
         */
    public int daysBetween(JulianDateStamp otherDate) {
            int difference = daysSpan(otherDate);
            return difference >= 0 ? difference : -difference;
    }
    
    /**
         * Returns span between two days. Returned value may be positive (when this date
         * is after the provided one) or negative (when comparing to future date).
         */
    public int daysSpan(JulianDateStamp otherDate) {
            int now = getJulianDayNumber();
            int then = otherDate.getJulianDayNumber();
            return now - then;
    }
    
    /**
         * Returns JDN. Note that JDN is not equal to {@link #integer}. It is calculated by
         * rounding to the nearest integer.
         */
    public int getJulianDayNumber() {
            if (fraction >= 0.5) {
                return integer + 1;
            }
            return integer;
    }
     
  • 相关阅读:
    4.5计算机网络笔记
    3.29计算机网络笔记
    3.22计算机网络笔记
    3.15计算机网络笔记
    用int类型表示最大公倍数
    markdown入门
    learning by doing
    技术博客(初用markdown)。
    物联网PPT智能家居王思齐和陈由钧第10组
    第六次java作业
  • 原文地址:https://www.cnblogs.com/luoxiaolei/p/5278624.html
Copyright © 2011-2022 走看看