国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

使用java.util.Calendar返回間隔天數

2019-11-18 13:43:52
字體:
來源:轉載
供稿:網友

  使用SimpleDateFormat,規定好格式,parser出錯即為非法/** * Calculates the number of days between two calendar days in a manner * which is independent of the Calendar type used. * * @param d1    The first date. * @param d2    The second date. * * @return      The number of days between the two dates.  Zero is *              returned if the dates are the same, one if the dates are *              adjacent, etc.  The order of the dates *              does not matter, the value returned is always >= 0. *              If Calendar types of d1 and d2 *              are different, the result may not be accurate. */static int getDaysBetween (java.util.Calendar d1, java.util.Calendar d2) {    if (d1.after(d2)) {  // swap dates so that d1 is start and d2 is end        java.util.Calendar swap = d1;        d1 = d2;        d2 = swap;    }    int days = d2.get(java.util.Calendar.DAY_OF_YEAR) -               d1.get(java.util.Calendar.DAY_OF_YEAR);    int y2 = d2.get(java.util.Calendar.YEAR);    if (d1.get(java.util.Calendar.YEAR) != y2) {        d1 = (java.util.Calendar) d1.clone();        do {            days += d1.getActualMaximum(java.util.Calendar.DAY_OF_YEAR);            d1.add(java.util.Calendar.YEAR, 1);        } while (d1.get(java.util.Calendar.YEAR) != y2);    }    return days;}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 河南省| 凤阳县| 鹤壁市| 株洲县| 馆陶县| 南开区| 彭州市| 平阴县| 达尔| 宁安市| 霞浦县| 刚察县| 迁安市| 桦甸市| 昔阳县| 辽中县| 丁青县| 莱芜市| 沧源| 鄄城县| 措勤县| 淅川县| 岗巴县| 竹北市| 肇州县| 神木县| 大石桥市| 策勒县| 辽宁省| 驻马店市| 大竹县| 台江县| 青神县| 安达市| 岳池县| 合阳县| 西宁市| 尼木县| 正定县| 合阳县| 理塘县|