前端获取后端传过来的当前月份只显示年月前端用the leaf后端用spring boot
前端可以使用JavaScript的Date对象来获取当前的年份和月份。例如:
var currentDate = new Date();
var currentYear = currentDate.getFullYear();
var currentMonth = currentDate.getMonth() + 1; // 注意月份是从0开始的,所以要加1
// 将年份和月份传给后端
// ...
后端使用Spring Boot可以使用java.time包下的YearMonth类来表示年月。例如:
import java.time.YearMonth;
// ...
YearMonth currentYearMonth = YearMonth.now();
int currentYear = currentYearMonth.getYear();
int currentMonth = currentYearMonth.getMonthValue();
// 将年份和月份传给前端
// ...
具体的传输方式可以根据实际情况选择,可以使用HTTP请求的参数或者JSON格式进行传输
原文地址: https://www.cveoy.top/t/topic/hCIG 著作权归作者所有。请勿转载和采集!