var date = new Date();
//月
var month = date.getMonth();
month = month + 1;
if ((month)<10) {
month = "0"+month;
}
//日
var riqi = date.getDate();
if (riqi<10) {
riqi = "0"+riqi;
}
//小时
var hour = date.getHours();
if (hour<10) {
hour = "0"+hour;
}
//分钟
var minute = date.getMinutes();
if (minute<10) {
minute = "0"+minute;
}
//秒钟
var second = date.getSeconds();
if (second<10) {
second = "0"+second;
}
//时间的格式为:2018-01-01 01:01:01
var time = date.getFullYear()+"-"+month+"-"+riqi+" "+hour+":"+minute+":"+second;