public String getDayOfMonth(int year, int month, int type){
// type爲1代表當月月初,2代表下個月月初,3代表上個月月初,4代表去年當月月初,5代表去年下個月月初
if (type == 2 || type == 5)
month = month + 1;
if (type == 3)
month = month - 1;
if (type == 4 || type == 5)
year = year - 1;
Calendar a = Calendar.getInstance();
a.set(Calendar.YEAR, year);
a.set(Calendar.MONTH, month - 1);
a.set(Calendar.DATE, 1);
// 格式化日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.format(a.getTime());
}
獲取當月月初、下個月月初、上個月月初、去年當月月初、去年下個月月初
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.