導航:首頁 > 編程語言 > java減月份

java減月份

發布時間:2024-04-27 23:19:47

『壹』 java月份相減

/**
* @param args
*/
public static Integer getDiffNum(Date startMonth,Date endMonth){


Integer monthNum = 0;
Integer yearNumber = 0;
Calendar startCalendar = Calendar.getInstance();
Calendar endCalendar = Calendar.getInstance();

startCalendar.setTime(startMonth);
endCalendar.setTime(endMonth);

yearNumber = endCalendar.get(endCalendar.YEAR) - startCalendar.get(endCalendar.YEAR);
monthNum = endCalendar.get(Calendar.MONTH) - startCalendar.get(Calendar.MONTH);

return yearNumber*12 + monthNum;
}

已經測試

『貳』 java鏈堜喚寰鐜錛屾瘡鏈堥兘鍚戝悗寰鐜6涓鏈堬紝姣斿傜幇鍦ㄦ槸5鏈堬紝鍚戝悗灝辨槸鍘誨勾鐨12鏈堜喚錛岃繖鏍風殑寰鐜鎬庝箞鍐欙紵奼傛寚鏁

publicstaticvoidmain(String[]args){
SimpleDateFormatsdf=newSimpleDateFormat("yyyy/MM/ddHH:mm:ss");
Datedate=newDate();
System.out.println(sdf.format(date));
System.out.println(sdf.format(subtractMarch(date,6)));
}
//鍑忔湀浠
publicstaticDatesubtractMarch(Datedate,intnum){
Calendarcal=Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.MARCH,cal.get(Calendar.MARCH)-num);
returncal.getTime();
}

閱讀全文

與java減月份相關的資料

熱點內容
外國電視劇一般發布在什麼網站上 瀏覽:357
北京市網路加密系統 瀏覽:535
數碼編譯器怎麼看 瀏覽:716
女主角叫晚晚的小說 瀏覽:34
電影love百度雲 瀏覽:671
彼時曾相伴愛奇藝 瀏覽:129
趣拿app怎麼查周邊領取 瀏覽:365
男男搞基小電影 瀏覽:991
專門拍生孩子的電影 瀏覽:720
關於國共的電影 瀏覽:40
大陸拍到香港拍電影小說 瀏覽:585
java選擇性編譯 瀏覽:361
python創建一個全0數組 瀏覽:199
函數單獨進行編譯 瀏覽:974
李采潭蘑菇 瀏覽:229
紫軒小說手打版下載 瀏覽:59
電腦pdf閱讀器下載 瀏覽:772
30G電影下載 瀏覽:443
電影孝順女兒觀影問卷 瀏覽:472
怎麼自己造一個伺服器手機版 瀏覽:167