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

如何在NiFi中生成秒级Epoch时间并计算一分钟前的时间戳

实现精确到秒的UTC时间戳及一分钟前时间戳的Jolt配置方案

你的需求可以通过调整Jolt Spec的细节来实现,核心是将毫秒级时间戳转换为秒级,并确保最终输出为字符串格式,修正后的配置如下:

[
  {
    "operation": "default",
    "spec": {
      "currenttime": "=divide(${now():toNumber()}, 1000)"
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "currenttime": "=toString(@(1,currenttime))",
      "timeOneMinu": "=toString(=Subtract(@(1,currenttime), 60))"
    }
  }
]

关键调整说明:

  • 秒级时间戳生成:${now():toNumber()}默认返回毫秒级Epoch时间戳,通过=divide(..., 1000)将其转换为精确到秒的数值
  • 字符串格式转换:预期输出要求时间戳为字符串类型,因此在modify-overwrite-beta操作中,用=toString()将数字类型的时间戳转换为字符串
  • 一分钟前时间计算:通过=Subtract(@(1,currenttime), 60)对当前秒级时间戳减去60秒,再转换为字符串得到目标值

应用该配置后,输出将符合你的预期:

{
  "currenttime": "1662372281",
  "timeOneMinu": "1662372221"
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 11:54:28