File tree Expand file tree Collapse file tree 3 files changed +19
-5
lines changed
Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Original file line number Diff line number Diff line change 7070 "vitepress" : " ^1.6.3"
7171 },
7272 "dependencies" : {
73- "dayjs" : " ^1.10.6 " ,
73+ "dayjs" : " ^1.11.13 " ,
7474 "idb" : " ^8.0.0" ,
7575 "js-base64" : " ^3.7.7" ,
7676 "js-cookie" : " ^3.0.5" ,
Original file line number Diff line number Diff line change 1- import dayjs from 'dayjs' ;
1+ import baseDayJs from 'dayjs' ;
2+ import timezone from 'dayjs/plugin/timezone' ; // ES 2015
3+ import utc from 'dayjs/plugin/utc' ; // ES 2015
4+
5+ baseDayJs . extend ( utc ) ;
6+ baseDayJs . extend ( timezone ) ;
7+ // 默认时区
8+ const DEFAULT_TIMEZONE = 'Asia/Shanghai' ;
9+ /**
10+ * 将时间转换为默认时区
11+ * @param {string | number | Date } time - 输入时间
12+ * @return {dayjs.Dayjs } 带时区的Dayjs对象
13+ */
14+ const dayjs = ( ...args ) => baseDayJs ( ...args ) . tz ( DEFAULT_TIMEZONE ) ;
15+
216/**
317 * @category 枚举
418 * 日期和时间格式模式的枚举
@@ -74,7 +88,7 @@ export enum DateTimeFormat {
7488 FULL_DATETIME_ISO = 'YYYY-MM-DDTHH:mm:ssZ' ,
7589}
7690
77- type DateTimeInput = string | number | Date | dayjs . Dayjs ;
91+ type DateTimeInput = string | number | Date | baseDayJs . Dayjs ;
7892type FormatPattern = DateTimeFormat | string ;
7993/**
8094 * 一个日期时间格式化工具,可处理各种输入类型和格式化模式。
@@ -120,7 +134,7 @@ type FormatPattern = DateTimeFormat | string;
120134export const formatDateTime = (
121135 date : DateTimeInput ,
122136 format : FormatPattern = DateTimeFormat . STANDARD
123- ) : string | dayjs . Dayjs => {
137+ ) : string | baseDayJs . Dayjs => {
124138 const isValidFormat = Object . values < string > ( DateTimeFormat ) . includes ( format ) ;
125139
126140 if ( ! isValidFormat ) {
You can’t perform that action at this time.
0 commit comments