获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS"

/**
获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS”
*/
function getNowFormatDate() {
   var date = new Date();
   var month = date.getMonth() + 1;
   var strDate = date.getDate();
   
   var h = date.getHours();
   var m = date.getMinutes();
   var s = date.getSeconds();
   
   if (month >= 1 && month <= 9) {month = "0" + month;}
   if (strDate >= 0 && strDate <= 9) {strDate = "0" + strDate;}
   if (h >= 0 && h <= 9) {h = "0" + h;}
   if (m >= 0 && m <= 9) {m = "0" + m;}
   if (s >= 0 && s <= 9) {s = "0" + s;}
   
   var currentdate = date.getFullYear() + "-" + month + "-" + strDate+ " " + h + ":" + m + ":" + s;
   return currentdate;
}

你可能感兴趣的:(获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS")