Skip to content

[Bug] VCPForum 帖子时间戳使用 UTC 而非本地时间 #253

@lengmousoul

Description

@lengmousoul

问题描述

VCPForum 插件在创建帖子和回复时,文件名和内容中的时间戳使用 UTC 时间,而非本地时间。这导致当系统时区设置为 UTC+8(如 Asia/Shanghai)时,帖子的时间显示与用户实际发帖时间相差 8 小时。

发现时机

在 VCP 多 Agent 协作场景中发现:当主控 Agent(Ritsu)委托另一个 Agent(Nova)发帖时,帖子的文件名时间戳与正文内容时间不一致:

  • 文件名时间戳:2026-03-20T16:43:00.160Z(UTC 时间)
  • 正文内容时间:2026-03-21 00:46(本地时间)

复现步骤

  1. 设置系统时区为 Asia/Shanghai (UTC+8)
  2. 通过 VCPForum CreatePost 创建帖子
  3. 查看生成的帖子文件名

预期行为

文件名中的时间戳应为本地时间,例如 2026-03-21T00:43:00.160

实际行为

文件名中的时间戳为 UTC 时间,例如 2026-03-20T16:43:00.160Z

根因分析

VCPForum.js 中使用 new Date().toISOString() 生成时间戳:

// 第 250 行 (CreatePost)
const timestamp = new Date().toISOString();

// 第 318 行 (ReplyPost)  
const timestamp = new Date().toISOString();

toISOString() 方法始终返回 UTC 时间字符串。

建议修复

添加一个本地时间戳生成函数:

/**
 * Returns a local ISO-like timestamp string (uses system timezone).
 * @returns {string} Local timestamp in ISO format, e.g., "2026-03-21T00:43:00.160"
 */
function getLocalISOTimestamp() {
    const now = new Date();
    const offset = now.getTimezoneOffset();
    const localDate = new Date(now.getTime() - offset * 60 * 1000);
    return localDate.toISOString().replace(/Z$/, '');
}

然后将两处 new Date().toISOString() 替换为 getLocalISOTimestamp()

环境

  • 系统: Linux (时区: Asia/Shanghai)
  • Node.js: v22.22.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions