| @@ -42,6 +42,7 @@ export const timeFormat = (date, locale) => { | |||||
| let d; | let d; | ||||
| // 支援 LocalDateTime array | |||||
| if (Array.isArray(date)) { | if (Array.isArray(date)) { | ||||
| const [y, m, d1, h = 0, min = 0, s = 0] = date; | const [y, m, d1, h = 0, min = 0, s = 0] = date; | ||||
| d = dayjs(new Date(y, m - 1, d1, h, min, s)); | d = dayjs(new Date(y, m - 1, d1, h, min, s)); | ||||
| @@ -55,19 +56,17 @@ export const timeFormat = (date, locale) => { | |||||
| const minute = d.minute(); | const minute = d.minute(); | ||||
| if (locale === "en") { | if (locale === "en") { | ||||
| return minute === 0 | |||||
| ? d.format("h a") | |||||
| : d.format("h:mm a"); | |||||
| return d.format("h:mm a"); // 12:00 pm | |||||
| } | } | ||||
| // 中文顯示(香港慣用) | |||||
| const period = hour < 12 ? "上午" : "下午"; | const period = hour < 12 ? "上午" : "下午"; | ||||
| const h12 = hour % 12 === 0 ? 12 : hour % 12; | |||||
| if (minute === 0) { | if (minute === 0) { | ||||
| return `${period}${d.format("h時")}`; | |||||
| return `${period}${h12}時`; | |||||
| } | } | ||||
| return `${period}${d.format("h時mm分")}`; | |||||
| return `${period}${h12}時${minute}分`; | |||||
| }; | }; | ||||