parent
200494fcf3
commit
646162593e
@ -0,0 +1,22 @@ |
||||
module.exports =function dateFormat(format, date=null) { |
||||
if(!date){ |
||||
date = new Date() |
||||
} |
||||
const args = { |
||||
"M+": date.getMonth() + 1, |
||||
"d+": date.getDate(), |
||||
"h+": date.getHours(), |
||||
"m+": date.getMinutes(), |
||||
"s+": date.getSeconds(), |
||||
"q+": Math.floor((date.getMonth() + 3) / 3), |
||||
"S": date.getMilliseconds() |
||||
}; |
||||
if (/(y+)/.test(format)) |
||||
format = format.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length)); |
||||
for (let i in args) { |
||||
let n = args[i]; |
||||
if (new RegExp("(" + i + ")").test(format)) |
||||
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? n : ("00" + n).substr(("" + n).length)); |
||||
} |
||||
return format; |
||||
} |
Loading…
Reference in new issue