国产探花免费观看_亚洲丰满少妇自慰呻吟_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;}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 天门市| 罗城| 克什克腾旗| 安图县| 瑞昌市| 军事| 靖远县| 黑河市| 吉安县| 铜梁县| 繁峙县| 深泽县| 本溪市| 如皋市| 客服| 同江市| 镇江市| 英吉沙县| 读书| 蓬溪县| 彭泽县| 青川县| 武强县| 林芝县| 肇州县| 汕头市| 娱乐| 化隆| 静乐县| 宽甸| 阿克| 务川| 若羌县| 城固县| 五指山市| 陆川县| 宕昌县| 和顺县| 乐东| 云龙县| 张家界市|