Skip to content

Commit

Permalink
fix(blog): date string timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
northword committed Oct 8, 2024
1 parent ce37ec1 commit b62af3c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/.vitepress/data/blog.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ export default createContentLoader('blog/blog-repo/posts/!(_template|index).md',
})

function formatDate(raw: string): Post['date'] {
const date = new Date(raw)
date.setUTCHours(12)
const date = new Date(`${raw} UTC+8`)
return {
time: +date,
string: date.toLocaleDateString('en-US', {
string: date.toLocaleDateString('zh-CN', {
year: 'numeric',
month: 'long',
day: 'numeric',
Expand Down
2 changes: 1 addition & 1 deletion src/.vitepress/theme/components/BlogIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { data as posts } from '@data/blog.data'
function getDateTime(time: number) {
return new Date(time).toISOString()
return new Date(time).toLocaleString('zh-CN')
}
</script>

Expand Down

0 comments on commit b62af3c

Please sign in to comment.