30 lines
1.1 KiB
JavaScript
30 lines
1.1 KiB
JavaScript
// 时间戳转换为本地时间,格式为 YYYY/MM/DD hh:mm
|
|
export function TimestamptolocalTime(date) {
|
|
if (!date || isNaN(date)) return ''
|
|
|
|
const d = new Date(date)
|
|
const year = d.getFullYear()
|
|
const month = String(d.getMonth() + 1).padStart(2, '0')
|
|
const day = String(d.getDate()).padStart(2, '0')
|
|
const hours = String(d.getHours()).padStart(2, '0')
|
|
const minutes = String(d.getMinutes()).padStart(2, '0')
|
|
|
|
return `${year}/${month}/${day} ${hours}:${minutes}`
|
|
}
|
|
|
|
// 时间戳转换为北京时间,格式为 YYYY/MM/DD hh:mm
|
|
export function TimestampttoBeijingTime(date) {
|
|
if (!date || isNaN(date)) return ''
|
|
|
|
const d = new Date(date)
|
|
// 北京时间是 UTC+8
|
|
const beijingTime = new Date(d.getTime() + 8 * 60 * 60 * 1000)
|
|
const year = beijingTime.getUTCFullYear()
|
|
const month = String(beijingTime.getUTCMonth() + 1).padStart(2, '0')
|
|
const day = String(beijingTime.getUTCDate()).padStart(2, '0')
|
|
const hours = String(beijingTime.getUTCHours()).padStart(2, '0')
|
|
const minutes = String(beijingTime.getUTCMinutes()).padStart(2, '0')
|
|
|
|
return `${year}/${month}/${day} ${hours}:${minutes}`
|
|
}
|