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

View File

@ -24,17 +24,7 @@ export function getLatestUpdatedPost(a: AllItem, b: AllItem) {
return getDateSortByUpdateTime(b).getTime() - getDateSortByUpdateTime(a).getTime();
}
export function convertToBeijingTime(date: Date) {
const options = {
timeZone: "Asia/Shanghai",
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;
export function convertToGMT(date: Date) {
// Subtract 8 hours to convert Beijing time to GMT
return new Date(date.getTime() - 8 * 60 * 60 * 1000);
}