mirror of
https://github.com/ourongxing/newsnow.git
synced 2025-01-19 11:19:14 +08:00
17 lines
506 B
TypeScript
17 lines
506 B
TypeScript
import dayjs from "dayjs"
|
|
import utcPlugin from "dayjs/plugin/utc.js"
|
|
import timezonePlugin from "dayjs/plugin/timezone.js"
|
|
|
|
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()
|
|
}
|
|
|
|
export const day = dayjs
|