mirror of
https://github.com/KazooTTT/kazoottt-blog-v2.git
synced 2025-06-16 15:31:21 +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 { 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(
|
||||
|
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user