格式化日期对象
格式化日期对象
console.log(d.toLocaleDateString());
console.log(d.toLocaleString());
console.log(d.toLocaleTimeString());
-----原型封装------
对象 Date.prototype.formatDate = function (type) {
var date = new Date()
var year = date.getFullYear()
var mounth = +date.getMonth() + 1
var day = date.getDate()
if (type == "zh") {
return year + '年' + mounth + '月' + day + '日'
} else {
return year + type + mounth + type + day
}
}
var d2 = new Date()
console.log(d2.formatDate("/"));