Jelajahi Sumber

feat: 修改时间格式化函数,取消十二小时制

zhouyuhao 6 bulan lalu
induk
melakukan
81ec198099
1 mengubah file dengan 9 tambahan dan 3 penghapusan
  1. 9 3
      src/utils/tools.ts

+ 9 - 3
src/utils/tools.ts

@@ -6,11 +6,17 @@ const formatString = computed(() => {
   return userStore.dateFormat || 'MM/DD/YYYY'
 })
 
-export const formatTimezone = (time: string, timezone?: string) => {
+export const formatTimezone = (time: string, timezone?: string, is12HourClock?: boolean) => {
   if (!time) return '--'
   let formattedTime = ''
   if (time.length > 12) {
-    formattedTime = moment(time).format(`${formatString.value} hh:mm A`)
+    if (is12HourClock) {
+      // 如果是12小时制,使用12小时制格式化
+      formattedTime = moment(time).format(`${formatString.value} hh:mm A`)
+    } else {
+      // 如果是24小时制,使用24小时制格式化
+      formattedTime = moment(time).format(`${formatString.value} HH:mm`)
+    }
     if (!timezone) {
       return formattedTime
     }
@@ -41,7 +47,7 @@ export const getTimezone = (timezone: string, time?: string): string => {
 export const formatTimezoneByUTCorGMT = (time: string, timezone: string) => {
   if (!time) return '--'
   let formattedTime = ''
-  formattedTime = moment(time).format(`${formatString.value} hh:mm A`)
+  formattedTime = moment(time).format(`${formatString.value} hh:mm`)
   let gmtOffset = ''
   if (timezone != null) {
     const timeZoneOffset = moment.tz(time, timezone).format('Z')