转换为正确的日期时间格式 - dataweave
我有一个如下格式的请求
{
"updatedTime": "Mon Mar 14 15:34:47 NZDT 2022"
}
响应应转换为“yyyy-MM-dd'T'HH:mm:ss”
{
"updatedTime": "2022-03-14'T'15:34:47"
}
我还参考了 Mule 文档 https://docs.mulesoft.com/dataweave/2.3/dataweave-cookbook-format-dates。有什么想法吗?感谢
使用 Mule4、Dataweave 2.0
I have a request coming as below format
{
"updatedTime": "Mon Mar 14 15:34:47 NZDT 2022"
}
The response should be converted to "yyyy-MM-dd'T'HH:mm:ss"
{
"updatedTime": "2022-03-14'T'15:34:47"
}
I also referred to Mule docs https://docs.mulesoft.com/dataweave/2.3/dataweave-cookbook-format-dates. Any thoughts? Thanks
Using Mule4, Dataweave 2.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该使用您共享的文档链接中的模式字符并构建整个日期的模式。您还可以搜索有关 Java 时间包模式的示例,DataWeave 日期/时间模式正是基于这些模式。
可能不太明显的是使用 patter
zz
表示时区,使用eee
表示本地化日期名称。You should use the patterns characters in the documentation link you shared and construct the pattern for the whole date. You can also search for examples on the Java time package patterns, which are the ones in which DataWeave date/time patterns are based on.
The ones that perhaps are not obvious are to use patter
zz
for the timezone andeee
for the localized day name.转换给定输入的另一种方法是
Another way of transforming the given input is
虽然
@aled
的答案是正确的,但我真的很喜欢 从 Dataweave 更新运算符,然后您可以重写 Dataweave,如下所示:
While the answer of
@aled
is correct I really like the update operator from Dataweave and than you can rewrite the Dataweave like:尝试这种方法日期解析
输出
Try this approach Date-Parsing
Output