1.日期时间带T和Z的Json格式字符串
例:2021-07-08T17:43:33.000Z
var ts = createTime.split("T");
var sub= ts[1].substring(0,8);//17:43:33
console.log("格式化后::"+ts[0]+" "+sub); //2021-07-08 17:43:33
2.获取日期格式化字符串 yyyy-MM-dd
getDate() {
const nowDate = new Date();
console.log(nowDate)
const date = {
year: nowDate.getFullYear(),
month: nowDate.getMonth() + 1,
date: nowDate.getDate(),
};
const newmonth = date.month >= 10 ? date.month : "0" + date.month;
const day = date.date >= 10 ? date.date : "0" + date.date;
return date.year + "-" + newmonth + "-" + day;
}