https://www.coder.work/article/5115331#google_vignette
import moment from 'moment'
let val = dataRow[key]
let col = this.getColByKey('xxx', key) // 获取列配置
if (col.type && col.type == 'date' && col.format) { // 是日期格式
let format = col.format.replace(/y/g, 'Y').replace(/d/g, 'D') // moment 中格式化不一样 YYYY-MM-DD HH:mm:ss
// 有效日期
if (moment(val, format, true).isValid() || moment(val).isValid()) {
if (typeof val == 'number') {
const changeDate = timeNum => {
const d = timeNum - 1
const t = Math.round((d - Math.floor(d)) * 24 * 60 * 60)
return moment(new Date(1900, 0, d, 0, 0, t)).format(format)
}
val = changeDate(val)
} else {
val = moment(val).format(format)
}
} else {
val = ''
}
}
网友评论