Timezone 时区
Timezone 模块处理时区相关的功能。
功能特性
1. 时区配置
yaml
timezone:
default: "Asia/Shanghai" # 默认时区
auto_detect: true # 自动检测用户时区
format: "YYYY-MM-DD HH:mm:ss Z"2. 时区转换
typescript
// 获取用户时区
const userTz = await agent.timezone.getUserTimezone(userId);
// 转换时区
const localTime = agent.timezone.convert(utcTime, 'Asia/Shanghai');
// 格式化时间
agent.timezone.format(time, {
format: 'YYYY年M月D日 H:mm',
locale: 'zh-CN'
});3. 定时任务
yaml
cron:
timezone: "Asia/Shanghai" # 定时任务使用的时区
jobs:
- id: "daily_report"
schedule: "0 9 * * *" # 每天早上9点
timezone: "Asia/Shanghai"使用场景
- 定时消息发送
- 用户时间显示
- 计划任务调度