1. 转换为:2020-7-9
var d = new Date() function date(date) { var nowdate = new Date(date).toLocaleDateString().replace(///g, '-') return nowdate } console.log(date(d));
2. 转换为2020/7/9
var d = new Date() function date(date) { var nowdate = new Date(date).toLocaleDateString() return nowdate } console.log(date(d));
3. 转换为2020-07-09 11:30:23
var d = new Date() function date(now) { // var now = new Date(), y = now.getFullYear(), m = ("0" + (now.getMonth() + 1)).slice(-2), d = ("0" + now.getDate()).slice(-2); return y + "-" + m + "-" + d + " " + now.toTimeString().substr(0, 8); } console.log(date(d));