You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Google Workflow YAML中生成指定日期格式的时间戳

在Cloud Workflow中生成yyyy-mm-dd格式的日期后缀

你可以直接通过time.format函数的第二个参数指定自定义格式,Cloud Workflow采用Go语言的时间格式化规则,只需使用参考时间Mon Jan 2 15:04:05 MST 2006对应的占位符来构建目标格式。

核心解法

要生成yyyy-mm-dd格式的日期,使用以下代码:

${time.format(sys.now(), "2006-01-02")}

格式规则说明

Go的时间格式化是通过参考时间的对应片段来定义格式的,关键对应关系:

  • 2006 → 4位年份(yyyy)
  • 01 → 2位月份(mm)
  • 02 → 2位日期(dd)
  • 15 → 24小时制小时
  • 04 → 分钟
  • 05 → 秒钟

完整Workflow示例片段

main:
  steps:
    - generateFormattedDate:
        assign:
          - targetDate: ${time.format(sys.now(), "2006-01-02")}
          - outputFileName: ${concat("my-output-file-", targetDate, ".csv")}
    - logFileName:
        call: sys.log
        args:
          text: ${concat("即将创建输出文件:", outputFileName)}

如果需要包含时间部分(如yyyy-mm-dd HH:mm:ss),只需调整格式字符串为:

${time.format(sys.now(), "2006-01-02 15:04:05")}

内容的提问来源于stack exchange,提问作者RaptorX

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 18:10:36