1、HTML/JQ代码:
jQuery获取当前时间(年/月/日 时:分:秒)function getNowDateTime(){
var now = new Date();
var year = now.getFullYear();
var month = (now.getMonth() + 1) < 10 ? '0' + (now.getMonth() + 1) : now.getMonth() + 1;
var dates = now.getDate() < 10 ? '0' + now.getDate() : now.getDate();
var hours = now.getHours() < 10 ? "0" + now.getHours() : now.getHours();
var minutes = now.getMinutes() < 10 ? '0' + now.getMinutes() : now.getMinutes();
var seconds = now.getSeconds() < 10 ? '0' + now.getSeconds() : now.getSeconds();
return year + "/" + month + "/" + dates + " " + hours + ":" + minutes + ":" + seconds;
}
$(function(){
console.log(getNowDateTime());
})
2、效果截图: