Skip to content

Commit

Permalink
添加时间解析
Browse files Browse the repository at this point in the history
  • Loading branch information
master1lan committed Jan 2, 2023
1 parent 4d6cde0 commit bea0900
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"preview": "vite preview"
},
"dependencies": {
"dayjs": "^1.11.7",
"imagesloaded": "^5.0.0",
"masonic": "^3.7.0",
"nanoid": "^4.0.0",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion src/routers/photo.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import getrealtiveTime from "@utils/time";
export default function PhotoPage() {
return <h1>这里是photographs页面</h1>;
const time = getrealtiveTime(1672570122);
return (
<>
<h1>这里是photographs页面</h1>
<p>
<span>{time}</span>
</p>
</>
);
}
9 changes: 9 additions & 0 deletions src/utils/time/index.ts
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit bea0900

Please sign in to comment.