有的时候,前端直接将日期输出,会将时分秒一起输出出来,如图:
但有的时候,我们只需要前面的日期(2020-08-04),在前端加个转换即可。
function changeDateFormat(cellval) {
if (cellval) {
var date = new Date(cellval);
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
return date.getFullYear() + "-" + month + "-" + currentDate;
}
return "";
}