CN-746: 更换时间选择器实现方案

This commit is contained in:
刘洪洪
2022-10-26 18:59:53 +08:00
parent 04e4371ac1
commit c2c3898d5b
3 changed files with 108 additions and 78 deletions

View File

@@ -69,3 +69,26 @@ export function dateFormatToUTC (date, format = 'YYYY-MM-DD HH:mm:ss') {
d = window.$dayJs(d).tz().format(format)
return d
}
/**
* 时间戳转年月日时分秒置于数组中配合el-date-picker使用
* @param time
* @returns {number[]}
*/
export function timestampToList (time) {
// 根据地址获取当前时区
const newTimezone = window.$dayJs.tz().utcOffset() / 60
// 缓存的本地时区
const localTimezone = parseInt(localStorage.getItem(storageKey.timezoneLocalOffset))
const date = new Date(getMillisecond(time + (newTimezone - localTimezone) * 3600))
const Y = date.getFullYear()
const M = date.getMonth()
const D = date.getDate()
const H = date.getHours()
const m = date.getMinutes()
const s = date.getSeconds()
const arr = [Y, M, D, H, m, s]
return arr
}