feat: 绑定日期过滤组件

This commit is contained in:
fit2cloud-chenyw
2021-05-20 22:14:07 +08:00
parent 20c0b4b68d
commit 4f8f9080cf
2 changed files with 53 additions and 0 deletions

View File

@@ -2,6 +2,26 @@
* Created by PanJiaChen on 16/11/18.
*/
export function dateFormat(date, fmt) {
let ret
const opt = {
'y+': date.getFullYear().toString(), // 年
'M+': (date.getMonth() + 1).toString(), // 月
'd+': date.getDate().toString(), // 日
'H+': date.getHours().toString(), // 时
'm+': date.getMinutes().toString(), // 分
's+': date.getSeconds().toString() // 秒
// 有其他格式化字符需求可以继续添加,必须转化成字符串
}
for (const k in opt) {
ret = new RegExp('(' + k + ')').exec(fmt)
if (ret) {
fmt = fmt.replace(ret[1], (ret[1].length === 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, '0')))
}
}
return fmt
}
/**
* Parse the time to string
* @param {(Object|string|number)} time