JavaScript的获取日期
获取日期
new Date();
new Date().getFullYear()
new Date().getMonth()+1
new Date().getDay()
new Date().getDate()
new Date().getHours()
new Date().getMinutes()
new Date().getSeconds()
new Date().getMilliseconds()
new Date().getTime()
var b = new Date().toLocaleDateString()
console.log(b);
var c = new Date().toLocaleTimeString()
console.log(c);
var d = new Date().toLocaleString()
console.log(d);
var weeks = ['周日','周一','周二','周三','周四','周五','周六']
var week = weeks[new Date().getDay()]
console.log(week,new Date().getMonth()+1,new Date().getHours());
function pd2(value) {
return value > 9 ? value : '0' + value
}
console.log(new Date().getFullYear() + '-' + pd2(new Date().getMonth() + 1) + '-' + pd2(new Date().getDate()));
console.log(pd2(new Date().getHours()) + ':' + pd2(new Date().getMinutes()) + ':' + pd2(new Date().getSeconds()));