fix: 格式时间-到指定时区
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
// 依赖来源 https://github.com/iamkun/dayjs
|
||||
import dayjs from 'dayjs';
|
||||
import utc from 'dayjs/plugin/utc'; // 导入 UTC 插件
|
||||
// 应用 UTC 插件
|
||||
dayjs.extend(utc);
|
||||
|
||||
// 导入本地化语言并设为默认使用,只需要全局有引入就行
|
||||
// import('dayjs/locale/zh-cn');
|
||||
@@ -73,6 +76,21 @@ export function diffValue(
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式时间-到指定时区
|
||||
* @param date 可转的Date对象
|
||||
* @param utcOffset 分钟偏移量
|
||||
* @param formatStr 时间格式 默认YYYY-MM-DD HH:mm:ss
|
||||
* @returns 时间格式字符串
|
||||
*/
|
||||
export function parseDateToStrByUTCOffset(
|
||||
date: string | number | Date,
|
||||
utcOffset: number,
|
||||
formatStr: string = YYYY_MM_DD_HH_MM_SS
|
||||
): string {
|
||||
return dayjs(date).utcOffset(utcOffset).format(formatStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化秒值为 ?h?m?s
|
||||
* @param seconds 2558 秒
|
||||
@@ -83,7 +101,7 @@ export function parseDuration(seconds: number | string) {
|
||||
const duration = new Date(seconds * 1000);
|
||||
const hours = duration.getUTCHours();
|
||||
const minutes = duration.getUTCMinutes();
|
||||
const secondsLeft = duration.getUTCSeconds();
|
||||
const secondsLeft = duration.getUTCSeconds();
|
||||
if (+hours > 0) {
|
||||
return `${hours}h${minutes}m${secondsLeft}s`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user