获取当前的日期时间的js函数,格式为“yyyy-MM-dd hh:mm:ss”

2023-06-08,,

 //获取当前的日期时间函数,格式为“yyyy-MM-dd hh:mm:ss”
function getNowFormatDate(date) {
if (date == null) {
var date = new Date();
}
var seperator1 = "-";
var seperator2 = ":";
var month = date.getMonth() + 1;
if (month >= 1 && month <= 9) {
month = "0" + month;
}
var strDate = date.getDate();
if (strDate >= 0 && strDate <= 9) {
strDate = "0" + strDate;
}
var hour = date.getHours();
if (hour >= 0 && hour <= 9) {
hour = "0" + hour;
}
var minute = date.getMinutes();
if (minute >= 0 && minute <= 9) {
minute = "0" + minute;
}
var sec = date.getSeconds();
if (sec >= 0 && sec <= 9) {
sec = "0" + sec;
}
var currentdate = date.getFullYear() + seperator1 + month + seperator1
+ strDate + " " + hour + seperator2 + minute
+ seperator2 + sec;
return currentdate;
}

获取当前的日期时间的js函数,格式为“yyyy-MM-dd hh:mm:ss”的相关教程结束。

《获取当前的日期时间的js函数,格式为“yyyy-MM-dd hh:mm:ss”.doc》

下载本文的Word格式文档,以方便收藏与打印。