中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

java日期的加減

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
private static final String DATE_NUMBER_PATTERN = "yyyyMMdd";

定義日期返回的類型

/**
* 由yyyyMMdd格式的字符串返回日期
* 
* @param date
* @return
*/
public static Date numberToDate(String string) {
if (string == null)
return null;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
DateUtilsC.DATE_NUMBER_PATTERN);


try {
return simpleDateFormat.parse(string);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


return null;

}

對傳過來的日期操作。!

       Date dealDate = DateUtilsC.numberToDate(dealDateStr);
Date endDate = DateUtilsC.numberToDate(endDateStr);
// 獲取日歷控件
Calendar cal = Calendar.getInstance();
// 加1天后的開始日期
cal.clear();
cal.setTime(dealDate);
cal.add(Calendar.DAY_OF_YEAR, 1);
Date dealDateD1 = cal.getTime();
// 開始日期與結(jié)束日期相差1天內(nèi)
if(!dealDateD1.before(endDate)){
return  "01";
}
// 加7天后的開始日期
cal.clear();
cal.setTime(dealDate);
cal.add(Calendar.DAY_OF_YEAR, 7);
Date dealDateD7 = cal.getTime();
// 開始日期與結(jié)束日期相差7天內(nèi)
if(!dealDateD7.before(endDate)){
return  "02";
}
// 加14天后的開始日期
cal.clear();
cal.setTime(dealDate);
cal.add(Calendar.DAY_OF_YEAR, 14);
Date dealDateD14 = cal.getTime();
// 開始日期與結(jié)束日期相差14天內(nèi)
if(!dealDateD14.before(endDate)){
return  "03";
}
// 加21天后的開始日期
cal.clear();
cal.setTime(dealDate);
cal.add(Calendar.DAY_OF_YEAR, 21);
Date dealDateD21 = cal.getTime();
// 開始日期與結(jié)束日期相差21天內(nèi)
if(!dealDateD21.before(endDate)){
return  "04";
}
// 加1個月后的開始日期
cal.clear();
cal.setTime(dealDate);
cal.add(Calendar.MONTH, 1);
Date dealDateM1 = cal.getTime();
// 開始日期與結(jié)束日期相差1月內(nèi)
if(!dealDateM1.before(endDate)){
return  "05";
}
// 加3個月后的開始日期
cal.clear();
cal.setTime(dealDate);
cal.add(Calendar.MONTH, 3);
Date dealDateM3 = cal.getTime();
// 開始日期與結(jié)束日期相差3月內(nèi)
if(!dealDateM3.before(endDate)){
return  "06";
}
// 加6個月后的開始日期
cal.clear();
cal.setTime(dealDate);
cal.add(Calendar.MONTH, 6);
Date dealDateM6 = cal.getTime();
// 開始日期與結(jié)束日期相差6月內(nèi)
if(!dealDateM6.before(endDate)){
return  "07";
}
// 加9個月后的開始日期
cal.clear();
cal.setTime(dealDate);
cal.add(Calendar.MONTH, 9);
Date dealDateM9 = cal.getTime();
// 開始日期與結(jié)束日期相差1月內(nèi)
if(!dealDateM9.before(endDate)){
return  "08";
}
// 加一年后的開始日期
cal.clear();
cal.setTime(dealDate);
cal.add(Calendar.YEAR, 1);
Date dealDateY1 = cal.getTime();
// 開始日期與結(jié)束日期相差1月內(nèi)
if(!dealDateY1.before(endDate)){
return  "09";
}
return null;
} 

標(biāo)簽:

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:備份壓縮mysql 數(shù)據(jù)庫

下一篇:mysql計算日期之間相差的天數(shù)