fix(date): replace Beijing time conversion with GMT conversion

This commit is contained in:
KazooTTT
2025-04-01 23:21:59 +08:00
parent f816128ccc
commit 827e6eeadf
2 changed files with 5 additions and 15 deletions

View File

@ -1,6 +1,6 @@
import { getAllPosts } from "@/data/post"; import { getAllPosts } from "@/data/post";
import { siteConfig } from "@/site.config"; import { siteConfig } from "@/site.config";
import { collectionDateSort, convertToBeijingTime } from "@/utils/date"; import { collectionDateSort, convertToGMT } from "@/utils/date";
import rss from "@astrojs/rss"; import rss from "@astrojs/rss";
import MarkdownIt from "markdown-it"; import MarkdownIt from "markdown-it";
import sanitizeHtml from "sanitize-html"; import sanitizeHtml from "sanitize-html";
@ -25,7 +25,7 @@ export const GET = async () => {
return { return {
title: post.data.title, title: post.data.title,
description: (post.data.description ?? "") + "\t" + tagStr, description: (post.data.description ?? "") + "\t" + tagStr,
pubDate: convertToBeijingTime(post.dateToCmp), pubDate: convertToGMT(post.dateToCmp),
link: `posts/${post.id}/`, link: `posts/${post.id}/`,
content: post.body content: post.body
? sanitizeHtml( ? sanitizeHtml(

View File

@ -24,17 +24,7 @@ export function getLatestUpdatedPost(a: AllItem, b: AllItem) {
return getDateSortByUpdateTime(b).getTime() - getDateSortByUpdateTime(a).getTime(); return getDateSortByUpdateTime(b).getTime() - getDateSortByUpdateTime(a).getTime();
} }
export function convertToBeijingTime(date: Date) { export function convertToGMT(date: Date) {
const options = { // Subtract 8 hours to convert Beijing time to GMT
timeZone: "Asia/Shanghai", return new Date(date.getTime() - 8 * 60 * 60 * 1000);
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
};
const formatter = new Intl.DateTimeFormat("zh-CN", options as Intl.DateTimeFormatOptions);
const formattedDate = formatter.format(date);
return formattedDate;
} }