简体   繁体   English

如何使用Dataweave Mule将字符串转换为Datetime

[英]How to convert a String to Datetime using Dataweave Mule

I have the following string 20170912113456 and i want to convert it to this format 2017/09/12 11:34:56 using Dataweave Mule. 我有以下字符串20170912113456 ,我想使用Dataweave Mule将其转换为此格式2017/09/12 11:34:56 Any ideas about how to do it ? 关于如何做的任何想法?

I would recommend first converting your input date string into a Dataweave localdatetime object. 我建议先将您输入的日期字符串转换为Dataweave localdatetime对象。 Then you can output the date object back to a string of any format. 然后,您可以将日期对象输出回任何格式的字符串。

%dw 1.0
%output application/json
---
formattedDate: flowVars.date as :localdatetime{format: "yyyyMMddHHmmss"} as :string{format:"yyyy/mm/dd HH:mm:ss"}

If you interested in learning the inner-working check out my converting string dates to Java Date Objects in Mule tutorial, https://youtu.be/XqI_Kii9RzA 如果您有兴趣学习内部工作,请在Mule教程中查看将字符串日期转换为Java Date Objects的方法, https://youtu.be/XqI_Kii9RzA

You can try few things like formatting to data and then to string based on below example. 您可以根据以下示例尝试一些事情,例如先格式化为数据然后格式化为字符串。

myDate: ((payload as :string) as :date {format: "yyyyMMdd"}) as :string {format: "MM-dd-yyyy"} myDate:((payload as:string)as:date {format:“ yyyyMMdd”})as:string {format:“ MM-dd-yyyy”}

For a better understanding the Date Time operations please go through below link. 为了更好地了解“日期时间”操作,请通过下面的链接。

https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-operators#date-time-operations https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-operators#date-time-operations

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM