获取当前时间
2018-06-29 本文已影响0人
SangFall
// 获取当前时间
function getNowFormatDate() {
var date = new Date();
var year = date.getFullYear(); //年
var month = date.getMonth() + 1; //月
var day = date.getDate(); //日
var hour = date.getHours(); //时
var minute = date.getMinutes(); //分
var second = date.getSeconds(); //秒
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (day >= 0 && day <= 9) {
day = "0" + day;
}
if (hour >= 0 && hour <= 9) {
hour = "0" + hour;
}
if (minute >= 0 && minute <= 9) {
minute = "0" + minute;
}
if (second >= 0 && second <= 9) {
second = "0" + second;
}
var currentdate = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
return currentdate;
}