[index.js] 增加 formatDate 方法;[unisocket.js] event 改名 skevent
This commit is contained in:
29
index.js
29
index.js
@@ -93,4 +93,33 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
formatDate(date, format){
|
||||
if (!(date instanceof Date)){
|
||||
date = new Date(date)
|
||||
}
|
||||
if (!date.toJSON()) {
|
||||
date = new Date()
|
||||
}
|
||||
|
||||
format = (format && typeof format==='string')
|
||||
? format
|
||||
: 'yyyy-mm-dd HH:MM:SS'
|
||||
let o = {
|
||||
'm+': date.getMonth() + 1, //月份
|
||||
'q+': Math.floor((date.getMonth() + 3) / 3), //季度
|
||||
'd+': date.getDate(), //日
|
||||
'H+': date.getHours(), //小时
|
||||
'M+': date.getMinutes(), //分
|
||||
'S+': date.getSeconds(), //秒
|
||||
's': date.getMilliseconds() //毫秒
|
||||
}
|
||||
if (/(y+)/.test(format))
|
||||
format = format.replace(RegExp.$1, (`${date.getFullYear()}`).substr(4 - RegExp.$1.length))
|
||||
for (var k in o){
|
||||
if (new RegExp(`(${k})`).test(format))
|
||||
format = format.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : ((`00${o[k]}`).substr((`${o[k]}`).length)))
|
||||
}
|
||||
return format
|
||||
},
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user