fix: 服务器时间格式化指定时区

This commit is contained in:
TsMask
2025-05-30 14:16:31 +08:00
parent d6a82f2034
commit 319f03abfd

View File

@@ -46,17 +46,17 @@ export function parseDateToStr(
/**
* 格式时间
* @param date 可转的Date对象
* @param offset 时间格式 默认 RFC3339
* @param offset 时间格式 默认 +0000
* @returns 时间格式字符串
*/
export function parseDateUTCToStr(
date: string | number | Date,
offset: string = '+0000'
): string {
// 将时间戳转换为 UTC 时间
const utcTime = dayjs.utc(date);
// 使用自定义时区偏移格式化时间
return utcTime.format(`YYYY-MM-DD HH:mm:ss [UTC${offset}]`);
return dayjs
.utc(date) // 将时间戳按 UTC 时间
.tz(offset) // 使用时区偏移
.format(`YYYY-MM-DD HH:mm:ss [UTC${offset}]`); // 格式化时间
}
/**