Skip to content

Commit 0b4f17a

Browse files
eecopiloteep
andauthored
feat: improve date formatting with better i18n support (#250)
This PR updates the date/time formatting to be locale-aware, supporting i18n. Previously, the format was hardcoded (e.g., YYYY-MM-DD), which did not adapt to international users' preferences. Now, it uses the user's local conventions to display dates and times. Co-authored-by: eep <[email protected]>
1 parent 84e48b2 commit 0b4f17a

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/mixins/mixin.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,32 @@ export const mixin = {
396396
},
397397

398398
dateFmt: function (value) {
399-
if (dayjs().isSame(value, 'year')) {
400-
return dayjs(value).format('DD/MM hh:mm')
401-
} else {
402-
return dayjs(value).format('DD/MM/YYYY hh:mm')
399+
const fileDate = new Date(value);
400+
const currentDate = new Date();
401+
const isSameYear = fileDate.getFullYear() === currentDate.getFullYear();
402+
403+
// 获取当前语言环境,默认为浏览器语言
404+
const locale = (window.localStorage.getItem('lang') || navigator.language || 'en').replace('_', '-');
405+
406+
if (isSameYear) {
407+
// 当前年份:只显示月日和时间
408+
return new Intl.DateTimeFormat(locale, {
409+
month: 'long',
410+
day: 'numeric',
411+
hour: '2-digit',
412+
minute: '2-digit',
413+
hour12: false
414+
}).format(fileDate)
403415
}
416+
// 不同年份:显示完整日期和时间
417+
return new Intl.DateTimeFormat(locale, {
418+
year: 'numeric',
419+
month: 'long',
420+
day: 'numeric',
421+
hour: '2-digit',
422+
minute: '2-digit',
423+
hour12: false
424+
}).format(fileDate)
404425
},
405426
coverType: function (item) {
406427
return item.is_dir ? "folder-cover" : "file-cover"

0 commit comments

Comments
 (0)