<script>
//获取当前时间
var date = new Date();
//格式化日期
function formatDate(date) {
var seconds = date.getSeconds();
var minute = date.getMinutes();
var hour = date.getHours();
var day = date.getDate();
var month = date.getMonth()+1;
var year = date.getFullYear();
seconds = seconds<10?"0"+seconds:seconds;
minute = minute<10?"0"+minute:minute;
hour = hour<10?"0"+hour:hour;
day = day<10?"0"+day:day;
month = month<10?"0"+month:month;
return str = year+"-"+month+"-"+day+" "+hour+":"+minute+":"+seconds;
}
var dates = formatDate(date);
console.log(dates);
</script>