From bea0900b0ca2e22274af3e572ebac86ca4418c6e Mon Sep 17 00:00:00 2001 From: master1lan <278457198@qq.com> Date: Mon, 2 Jan 2023 17:23:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=B6=E9=97=B4=E8=A7=A3?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + pnpm-lock.yaml | 6 ++++++ src/routers/photo.tsx | 11 ++++++++++- src/utils/time/index.ts | 9 +++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/utils/time/index.ts diff --git a/package.json b/package.json index fa638d9..486d223 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "preview": "vite preview" }, "dependencies": { + "dayjs": "^1.11.7", "imagesloaded": "^5.0.0", "masonic": "^3.7.0", "nanoid": "^4.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3786180..0b36ba9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,7 @@ specifiers: '@types/react-dom': ^18.0.9 '@types/react-lazy-load-image-component': ^1.5.2 '@vitejs/plugin-react-swc': ^3.0.0 + dayjs: ^1.11.7 imagesloaded: ^5.0.0 less: ^4.1.3 masonic: ^3.7.0 @@ -20,6 +21,7 @@ specifiers: vite: ^4.0.0 dependencies: + dayjs: 1.11.7 imagesloaded: 5.0.0 masonic: 3.7.0_react@18.2.0 nanoid: 4.0.0 @@ -519,6 +521,10 @@ packages: resolution: {integrity: sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==} dev: true + /dayjs/1.11.7: + resolution: {integrity: sha512-+Yw9U6YO5TQohxLcIkrXBeY73WP3ejHWVvx8XCk3gxvQDCTEmS48ZrSZCKciI7Bhl/uCMyxYtE9UqRILmFphkQ==} + dev: false + /debug/3.2.7: resolution: {integrity: sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==} peerDependencies: diff --git a/src/routers/photo.tsx b/src/routers/photo.tsx index 68b075c..3a0a6fc 100644 --- a/src/routers/photo.tsx +++ b/src/routers/photo.tsx @@ -1,3 +1,12 @@ +import getrealtiveTime from "@utils/time"; export default function PhotoPage() { - return
+ {time} +
+ > + ); } diff --git a/src/utils/time/index.ts b/src/utils/time/index.ts new file mode 100644 index 0000000..27eaf92 --- /dev/null +++ b/src/utils/time/index.ts @@ -0,0 +1,9 @@ +import dayJs from "dayjs"; +import realtiveTime from "dayjs/plugin/relativeTime"; +import "dayjs/locale/zh-cn"; +dayJs.locale("zh-cn"); +dayJs.extend(realtiveTime); + +export default function getrealtiveTime(time: number): string { + return dayJs(time).toNow(); +}