get时间
var d=new Date();
console.log(d.getFullYear());
console.log(d.getMonth());
console.log(d.getDate());
console.log(d.getDay());
console.log(d.getHours());
console.log(d.getMinutes());
console.log(d.getSeconds());
console.log(d.getTime());
set时间
var d=new Date();//2017-4-8
d.setDate(2);//2017-4-2
d.setYear(2015);//2015-4-2
console.log(d);
// Date有自动适配能力
d.setDate(32);//2015-5-2
console.log(d);
d.setMonth(12);
console.log(d);//2016-1-2
// 格式化日期
console.log(d.toLocaleString());
// d.toLocaleDateString();
console.log(d.toGMTString());
console.log(d.toUTCString());
转载于:https://www.cnblogs.com/xinxinxinxin/p/6687666.html