mirror of
https://github.com/KazooTTT/kazoottt-blog-v2.git
synced 2025-06-16 23:41:20 +08:00
fix(date): replace Beijing time conversion with GMT conversion
This commit is contained in:
@ -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(
|
||||||
|
@ -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;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user