2016-12-23T06:22:33
获取当前的日期时间 格式“YYYY-MM-DD HH:MM:SS”
function getNowFormatDate() {
let date = new Date();
let seperator1 = "-";
let seperator2 = ":";
let month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
let currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
+ " " + date.getHours() + seperator2 + date.getMinutes()
+ seperator2 + date.getSeconds();
return currentdate;
}
let f = function getNowFormatDate() {
let date = new Date();
let seperator1 = "-";
let seperator2 = ":";
let month = date.getMonth() + 1;
var strDate = date.getDate();
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
let currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
+ " " + date.getHours() + seperator2 + date.getMinutes()
+ seperator2 + date.getSeconds();
return currentdate;
}
let date = f()
console.log(669, data)
//输出 669 "2019-10-27 9:23:17"
RE: JavaScript开发笔记