日期与时间

日期与时间

适用范围

在以下情况使用此页面:

  • 你正在更改向模型或用户显示时间戳的方式
  • 你正在调试消息或系统提示输出中的时间格式

Clawdbot 默认为传输时间戳使用主机本地时间在系统提示中仅使用用户时区。提供商时间戳会被保留,以便工具保持其本机语义(当前时间可通过 session_status 获得)。

消息信封(默认本地)

入站消息用时间戳包装(分钟精度):

[Provider ... 2026-01-05 16:26 PST] message text

此信封时间戳默认为主机本地时间,无论提供商时区如何。

你可以覆盖此行为:

{
  agents: {
    defaults: {
      envelopeTimezone: "local", // "utc" | "local" | "user" | IANA timezone
      envelopeTimestamp: "on", // "on" | "off"
      envelopeElapsed: "on" // "on" | "off"
    }
  }
}
  • envelopeTimezone: "utc" 使用 UTC。
  • envelopeTimezone: "local" 使用主机时区。
  • envelopeTimezone: "user" 使用 agents.defaults.userTimezone(回退到主机时区)。
  • 使用明确的 IANA 时区(例如 "America/Chicago")来获得固定区域。
  • envelopeTimestamp: "off" 从信封标题中删除绝对时间戳。
  • envelopeElapsed: "off" 删除经过时间后缀(+2m 样式)。

示例

本地(默认):

[WhatsApp +1555 2026-01-18 00:19 PST] hello

用户时区:

[WhatsApp +1555 2026-01-18 00:19 CST] hello

已启用经过时间:

[WhatsApp +1555 +30s 2026-01-18T05:19Z] follow-up

系统提示:当前日期和时间

如果用户时区已知,系统提示包含一个专用的当前日期和时间部分,仅包含时区(无时钟/时间格式)以保持提示缓存稳定:

Time zone: America/Chicago

当智能体需要当前时间时,请使用 session_status 工具;状态卡包含时间戳行。

系统事件行(默认本地)

插入到智能体上下文中的排队系统事件使用与消息信封相同的时区选择(默认:主机本地)作为前缀时间戳:

System: [2026-01-12 12:19:17 PST] Model switched.

配置用户时区 + 格式

{
  agents: {
    defaults: {
      userTimezone: "America/Chicago",
      timeFormat: "auto" // auto | 12 | 24
    }
  }
}
  • userTimezone 为提示上下文设置用户本地时区
  • timeFormat 控制提示中的12h/24h 显示auto 遵循操作系统首选项。

时间格式检测(自动)

timeFormat: "auto" 时,Clawdbot 会检查操作系统首选项(macOS/Windows)并回退到区域设置格式。检测到的值每个进程缓存一次以避免重复的系统调用。

工具负载 + 连接器(原始提供商时间 + 标准化字段)

渠道工具返回提供商本机时间戳并添加标准化字段以保持一致性:

  • timestampMs:纪元毫秒(UTC)
  • timestampUtc:ISO 8601 UTC 字符串

原始提供商字段将被保留,因此不会丢失任何内容。

  • Slack:来自 API 的类似纪元的字符串
  • Discord:UTC ISO 时间戳
  • Telegram/WhatsApp:提供商特定的数字/ISO 时间戳

如果你需要本地时间,请使用已知时区在下游转换它。

相关文档