var now = new Date();
var year = now.getFullYear();
var month = (now.getMonth() + 1).toString().length < 2 ?
('0' + (now.getMonth() + 1)) : now.getMonth() + 1;
var date = now.getDate().toString().length < 2 ?
('0' + now.getDate()) : now.getDate();
var hour = now.getHours().toString().length < 2 ?
('0' + now.getHours()) : now.getHours();
var minute = now.getMinutes().toString().length < 2 ?
('0' + now.getMinutes()) : now.getMinutes();
var second = now.getSeconds().toString().length < 2 ?
('0' + now.getSeconds()) : now.getSeconds();
var date = year + "-" + month + "-" + date + "" +
hour + ":" + minute + ":" + second;
console.log(date, '---date--)
转载于:https://my.oschina.net/felumanman/blog/297719