12345678910111213141516171819202122 |
- import dayjs from "dayjs";
- import utc from 'dayjs/plugin/utc.js'; // 导入 UTC 插件
- import timezone from 'dayjs/plugin/timezone.js'; // 导入时区插件
- dayjs.extend(utc); // 加载 UTC 插件
- dayjs.extend(timezone); // 加载时区插件
- export function shanghaiTime () {
- // 获取当前时间
- const now = dayjs();
- // 设置为上海时区
- const shanghaiTime = now.tz('Asia/Shanghai');
- return shanghaiTime
- }
- export function shanghaiTimeFormat (time, formatStr = 'YYYY-MM-DD HH:mm:ss') {
- // 获取当前时间
- const now = dayjs(time);
- // 设置为上海时区
- const shanghaiTime = now.tz('Asia/Shanghai');
- return shanghaiTime.format(formatStr)
- }
|