/**
|
* Independent time operation tool to facilitate subsequent switch to dayjs
|
*/
|
// TODO 芋艿:【锁屏】可能后面删除掉
|
import dayjs from 'dayjs'
|
|
const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss'
|
const DATE_FORMAT = 'YYYY-MM-DD'
|
|
export function formatToDateTime(date?: dayjs.ConfigType, format = DATE_TIME_FORMAT): string {
|
return dayjs(date).format(format)
|
}
|
|
export function formatToDate(date?: dayjs.ConfigType, format = DATE_FORMAT): string {
|
return dayjs(date).format(format)
|
}
|
|
export const dateUtil = dayjs
|
export function getYMDHMS (timestamp: number | string | Date) {
|
const time = new Date(timestamp)
|
const year = time.getFullYear()
|
let month = time.getMonth() + 1 + ''
|
let date = time.getDate() + ''
|
let hours = time.getHours() + ''
|
let minute = time.getMinutes() + ''
|
let second = time.getSeconds() + ''
|
|
if (month < 10) { month = '0' + month }
|
if (date < 10) { date = '0' + date }
|
if (hours < 10) { hours = '0' + hours }
|
if (minute < 10) { minute = '0' + minute }
|
if (second < 10) { second = '0' + second }
|
return year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + second
|
}
|
export function getYMDHM0 (timestamp: number | string | Date) {
|
const time = new Date(timestamp)
|
const year = time.getFullYear()
|
let month = time.getMonth() + 1 + ''
|
let date = time.getDate() + ''
|
let hours = time.getHours() + ''
|
let minute = time.getMinutes() + ''
|
|
if (month < 10) { month = '0' + month }
|
if (date < 10) { date = '0' + date }
|
if (hours < 10) { hours = '0' + hours }
|
if (minute < 10) { minute = '0' + minute }
|
return year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + '00'
|
}
|
export function getYMD (timestamp: number | string | Date) {
|
const time = new Date(timestamp)
|
const year = time.getFullYear()
|
let month = time.getMonth() + 1 + ''
|
let date = time.getDate() + ''
|
let hours = time.getHours() + ''
|
let minute = time.getMinutes() + ''
|
let second = time.getSeconds() + ''
|
|
if (month < 10) { month = '0' + month }
|
if (date < 10) { date = '0' + date }
|
if (hours < 10) { hours = '0' + hours }
|
if (minute < 10) { minute = '0' + minute }
|
if (second < 10) { second = '0' + second }
|
return year + '-' + month + '-' + date
|
}
|
export function getYM (timestamp: number | string | Date) {
|
const time = new Date(timestamp)
|
const year = time.getFullYear()
|
let month = time.getMonth() + 1 + ''
|
let date = time.getDate() + ''
|
let hours = time.getHours() + ''
|
let minute = time.getMinutes() + ''
|
let second = time.getSeconds() + ''
|
|
if (month < 10) { month = '0' + month }
|
if (date < 10) { date = '0' + date }
|
if (hours < 10) { hours = '0' + hours }
|
if (minute < 10) { minute = '0' + minute }
|
if (second < 10) { second = '0' + second }
|
return year + '-' + month
|
}
|