This commit is contained in:
sijinhui
2024-04-26 22:52:35 +08:00
parent 84638d9364
commit 0b713200fd
3 changed files with 21 additions and 13 deletions

View File

@@ -1,3 +1,5 @@
import { addHours } from "date-fns";
export function getCurrentTime(now?: Date): string {
if (!now) {
const now = new Date();
@@ -16,3 +18,19 @@ export function getCurrentTime(now?: Date): string {
return formatter.format(now);
}
export function getCurStartEnd(now = new Date()) {
const startOfTheDayInTimeZone = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate(),
0,
0,
0,
);
const endOfTheDayInTimeZone = addHours(startOfTheDayInTimeZone, +24); // 当天的结束时间
return {
startOfTheDayInTimeZone,
endOfTheDayInTimeZone,
};
}