function getCurrentDate() {
var now = new Date();
var dataStr = now.getFullYear() + "-";
if (now.getMonth() + 1 < 10) {
dataStr += "0" + (now.getMonth() + 1);
} else {
dataStr += (now.getMonth() + 1);
}
dataStr += "-";
if (now.getDate() < 10) {
dataStr += "0" + now.getDate();
} else {
dataStr += now.getDate();
}
dataStr += " ";
if (now.getHours() < 10) {
dataStr += "0" + now.getHours();
} else {
dataStr += now.getHours();
}
dataStr += ":";
if (now.getMinutes() < 10) {
dataStr += "0" + now.getMinutes();
} else {
dataStr += now.getMinutes();
}
dataStr += ":";
if (now.getSeconds() < 10) {
dataStr += "0" + now.getSeconds();
} else {
dataStr += now.getSeconds();
}
$("#showCurrentTime").text(dataStr);
}
window.setInterval("getCurrentDate()", 1000);
原文地址:http://hundage.blog.51cto.com/3779401/1670637