feat: 修复奇安信浏览器时区格式错误
This commit is contained in:
@@ -17,6 +17,35 @@ export const RFC3339 = 'YYYY-MM-DDTHH:mm:ssZ';
|
|||||||
/**国际时间 列如:Thu, Nov 14 2024 10:19 GMT+08:00 */
|
/**国际时间 列如:Thu, Nov 14 2024 10:19 GMT+08:00 */
|
||||||
export const RFC822Z = 'ddd, MMM DD YYYY HH:mm [GMT]Z';
|
export const RFC822Z = 'ddd, MMM DD YYYY HH:mm [GMT]Z';
|
||||||
|
|
||||||
|
// 映射时区偏移量与IANA时区名称关联
|
||||||
|
export const offsetToIanaMap: Record<string, string> = {
|
||||||
|
'+0000': 'UTC',
|
||||||
|
'+0100': 'Europe/London',
|
||||||
|
'+0200': 'Europe/Paris',
|
||||||
|
'+0300': 'Europe/Moscow',
|
||||||
|
'+0400': 'Asia/Dubai',
|
||||||
|
'+0500': 'Asia/Karachi',
|
||||||
|
'+0600': 'Asia/Almaty',
|
||||||
|
'+0700': 'Asia/Bangkok',
|
||||||
|
'+0800': 'Asia/Shanghai',
|
||||||
|
'+0900': 'Asia/Tokyo',
|
||||||
|
'+1000': 'Australia/Sydney',
|
||||||
|
'+1100': 'Pacific/Noumea',
|
||||||
|
'+1200': 'Pacific/Fiji',
|
||||||
|
'-0100': 'America/Noronha',
|
||||||
|
'-0200': 'Atlantic/Azores',
|
||||||
|
'-0300': 'America/Argentina/Buenos_Aires',
|
||||||
|
'-0400': 'America/New_York',
|
||||||
|
'-0500': 'America/New_York',
|
||||||
|
'-0600': 'America/Chicago',
|
||||||
|
'-0700': 'America/Denver',
|
||||||
|
'-0800': 'America/Los_Angeles',
|
||||||
|
'-0900': 'Pacific/Honolulu',
|
||||||
|
'-1000': 'Pacific/Honolulu',
|
||||||
|
'-1100': 'Pacific/Pago_Pago',
|
||||||
|
'-1200': 'Pacific/Kwajalein',
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 格式时间字符串
|
* 格式时间字符串
|
||||||
* @param dateStr 时间字符串
|
* @param dateStr 时间字符串
|
||||||
@@ -53,9 +82,10 @@ export function parseDateUTCToStr(
|
|||||||
date: string | number | Date,
|
date: string | number | Date,
|
||||||
offset: string = '+0000'
|
offset: string = '+0000'
|
||||||
): string {
|
): string {
|
||||||
|
const ianaTimezone = offsetToIanaMap[offset] || 'UTC';
|
||||||
return dayjs
|
return dayjs
|
||||||
.utc(date) // 将时间戳按 UTC 时间
|
.utc(date) // 将时间戳按 UTC 时间
|
||||||
.tz(offset) // 使用时区偏移
|
.tz(ianaTimezone) // 使用时区偏移
|
||||||
.format(`YYYY-MM-DD HH:mm:ss [UTC${offset}]`); // 格式化时间
|
.format(`YYYY-MM-DD HH:mm:ss [UTC${offset}]`); // 格式化时间
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user