newsnow/server/utils/date.ts

17 lines
506 B
TypeScript
Raw Normal View History

2024-10-03 13:16:14 +08:00
import dayjs from "dayjs"
2024-10-03 23:11:10 +08:00
import utcPlugin from "dayjs/plugin/utc.js"
import timezonePlugin from "dayjs/plugin/timezone.js"
2024-10-03 13:16:14 +08:00
dayjs.extend(utcPlugin)
dayjs.extend(timezonePlugin)
/**
* UTC
*/
export function tranformToUTC(date: string, format?: string, timezone: string = "Asia/Shanghai"): number {
if (!format) return dayjs.tz(date, timezone).valueOf()
return dayjs.tz(date, format, timezone).valueOf()
}
2024-10-08 20:49:19 +08:00
export const day = dayjs