返回当前时间的函数封装
以下是完整封装,可根据需要取年月日或时分秒
function getDateTime() {
var date = new Date();
year = date.getFullYear();
moth = date.getMonth() + 1; // 月份需加1
day = date.getDate();
hour = date.getHours() + 1; // 小时需加1
minute = date.getMinutes();
second = date.getSeconds();
month = checkTime(month);
day = checkTime(day);
hour = checkTime(hour);
minute = checkTime(minute);
second = checkTime(second);
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
return "" + year + "年" + month + "月" + day + "日" + hour + "时" + minute + "分" + second + "秒"
}
}