<el-date-picker
v-model="queryParam.yuedTime"
type="month"
placeholder="选择月"
@change="handleMonthChange">
</el-date-picker>
方式一:在前端处理 @change="handleMonthChange" ,增加此方法
handleMonthChange(value) {
const selectedDate = new Date(value);
const firstDayOfMonth = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), 2);//多加2天时间
// 将处理后的日期数据存入 queryParam.yuedTime
this.queryParam.yuedTime = firstDayOfMonth.toISOString(); // 这里可以根据后端接口的需求格式化日期数据
// alert(this.queryParam.yuedTime)
},
方法二:在后端处理,对月份增加一,然后进行相应处理
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String formattedDate = sdf.format(YuedTime);
Date dt=sdf.parse(formattedDate);
Calendar rightNow = Calendar.getInstance();
rightNow.setTime(dt);
rightNow.add(Calendar.MONTH,1);//日期加1个月
Date dt1=rightNow.getTime();
String reStr = sdf.format(dt1);
String reStr2=reStr.substring(0,4)+'-'+reStr.substring(4,6);