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

如何在DataWeave 2.0中将Twitter返回的created_at转换为datetime格式

DataWeave 2.0 转换Twitter created_at时间格式方案

核心实现逻辑是先将Twitter返回的时间字符串解析为DateTime类型,再按目标格式转成字符串即可。

核心代码示例

%dw 2.0
output application/json
---
{
    created_at: (payload.created_at as DateTime {format: "EEE MMM dd HH:mm:ss Z yyyy"}) as String {format: "yyyy-MM-dd HH:mm:ss"}
}

注意事项

  • 若运行环境默认Locale不是英文,解析英文的星期、月份缩写会报错,需手动指定英文Locale:
    payload.created_at as DateTime {format: "EEE MMM dd HH:mm:ss Z yyyy", locale: "en_US"}
  • 若需要转换为指定时区的时间,可在转字符串时添加时区参数,例如转成北京时间:
    (payload.created_at as DateTime {format: "EEE MMM dd HH:mm:ss Z yyyy", locale: "en_US"}) as String {format: "yyyy-MM-dd HH:mm:ss", timezone: "Asia/Shanghai"}

效果验证

输入示例:

{
"created_at": "Tue Sep 14 23:57:15 +0000 2021"
}

输出结果:

{
"created_at": "2021-09-14 23:57:15"
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.03 22:45:00