java 获取最近三个月的月初和月末日期
public static Map<String,String> getRecentThreeMonths(){
Map<String,String> dateMap = new LinkedHashMap<>();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
// 前两个月第一天
Calendar lastTwoC1 = Calendar.getInstance();
lastTwoC1.add(Calendar.MONTH,-2);
lastTwoC1.set(Calendar.DAY_OF_MONTH,1);
dateMap.put("lastTwoC1",format.format(lastTwoC1.getTime()) + " 00:00:00");
// 前两个月最后一天
Calendar lastTwoC2 = Calendar.getInstance();
lastTwoC2.add(Calendar.MONTH,-1);
lastTwoC2.set(Calendar.DAY_OF_MONTH,0);
dateMap.put("lastTwoC2",format.format(lastTwoC2.getTime()) + " 23:59:59");
// 前一个月第一天
Calendar lastOneC1 = Calendar.getInstance();
lastOneC1.add(Calendar.MONTH,-1);
lastOneC1.set(Calendar.DAY_OF_MONTH,1);
dateMap.put("lastOneC1",format.format(lastOneC1.getTime()) + " 00:00:00");
// 前一个月最后一天
Calendar lastOneC2 = Calendar.getInstance();
lastOneC2.set(Calendar.DAY_OF_MONTH,0);
dateMap.put("lastOneC2",format.format(lastOneC2.getTime()) + " 23:59:59");
// 当月第一天
Calendar cuurC1 = Calendar.getInstance();
cuurC1.add(Calendar.MONTH,0);
cuurC1.set(Calendar.DAY_OF_MONTH,1);
dateMap.put("cuurC1",format.format(cuurC1.getTime()) + " 00:00:00");
// 当月最后一天
Calendar cuurC2 = Calendar.getInstance();
cuurC2.set(Calendar.DAY_OF_MONTH,cuurC2.getActualMaximum(Calendar.DAY_OF_MONTH));
dateMap.put("cuurC2",format.format(cuurC2.getTime()) + " 23:59:59");
return dateMap;
}
邮箱:2754371607@qq.com
交友: 同款QQ号