更新
This commit is contained in:
38
src/utils/date.js
Normal file
38
src/utils/date.js
Normal file
@@ -0,0 +1,38 @@
|
||||
// 对Date的扩展,将 Date 转化为指定格式的String
|
||||
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
|
||||
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
|
||||
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
|
||||
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
|
||||
// eslint-disable-next-line no-extend-native
|
||||
Date.prototype.Format = function (fmt) {
|
||||
const o = {
|
||||
'M+': this.getMonth() + 1, // 月份
|
||||
'd+': this.getDate(), // 日
|
||||
'h+': this.getHours(), // 小时
|
||||
'm+': this.getMinutes(), // 分
|
||||
's+': this.getSeconds(), // 秒
|
||||
'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
|
||||
S: this.getMilliseconds() // 毫秒
|
||||
}
|
||||
const reg = /(y+)/
|
||||
if (reg.test(fmt)) {
|
||||
const t = reg.exec(fmt)[1]
|
||||
fmt = fmt.replace(t, (this.getFullYear() + '').substring(4 - t.length))
|
||||
}
|
||||
for (let k in o) {
|
||||
const regx = new RegExp('(' + k + ')')
|
||||
if (regx.test(fmt)) {
|
||||
const t = regx.exec(fmt)[1]
|
||||
fmt = fmt.replace(t, t.length === 1 ? o[k] : ('00' + o[k]).substring(('' + o[k]).length))
|
||||
}
|
||||
}
|
||||
return fmt
|
||||
}
|
||||
|
||||
export function formatTimeToStr(times, pattern) {
|
||||
let d = new Date(times).Format('yyyy-MM-dd hh:mm:ss')
|
||||
if (pattern) {
|
||||
d = new Date(times).Format(pattern)
|
||||
}
|
||||
return d.toLocaleString()
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { formatTimeToStr } from '@/utils/date'
|
||||
import { getDict } from '@/utils/dictionary'
|
||||
import { ref } from 'vue'
|
||||
|
||||
@@ -8,7 +9,14 @@ export const formatBoolean = (bool) => {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
export const formatDate = (time) => {
|
||||
if (time !== null && time !== '') {
|
||||
var date = new Date(time)
|
||||
return formatTimeToStr(date, 'yyyy-MM-dd hh:mm:ss')
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
export const filterDict = (value, options) => {
|
||||
// 递归查找函数
|
||||
const findInOptions = (opts, targetValue) => {
|
||||
|
||||
Reference in New Issue
Block a user