feat: 修复时区问题

This commit is contained in:
2026-07-07 23:49:06 +08:00
parent 3c9ef565b3
commit 4fe81f1e48
3 changed files with 25 additions and 9 deletions

9
.editorconfig Normal file
View File

@@ -0,0 +1,9 @@
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

View File

@@ -1,5 +1,10 @@
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
dayjs.extend(utc);
dayjs.extend(timezone);
export const formatDatetime = (date: string,format = 'YYYY-MM-DD HH:mm') => { export const formatDatetime = (date: string,format = 'YYYY-MM-DD HH:mm') => {
return dayjs(date).format(format); return dayjs(date).tz('Asia/Shanghai').format(format);
}; };

View File

@@ -9,6 +9,7 @@ interface Post {
summary: string; summary: string;
slug: string; slug: string;
cover: string; cover: string;
category_name: string;
published_at: string; published_at: string;
} }
@@ -28,7 +29,8 @@ const {list} = await http.get<ApiPageResponse<Post>>("post");
</div> </div>
<div class="post-content"> <div class="post-content">
<h2>{post.title}</h2> <h2>{post.title}</h2>
<p class="summary">{post.summary}</p> <p class="summary">summary:{post.summary}</p>
<p class="summary">category_name:{post.category_name}</p>
<div>{formatDatetime(post.published_at, 'YYYY 年 MM 月 DD 日')}</div> <div>{formatDatetime(post.published_at, 'YYYY 年 MM 月 DD 日')}</div>
</div> </div>
</a> </a>