简体   繁体   English

Mule Dataweave日期时间从完整转换为短

[英]Mule Dataweave Date Time Conversion from Full to Short

I am attempting to convert this datetime string from this format: 我正在尝试从以下格式转换此datetime字符串:

'Wed, 09 Aug 2017 20:16:59 +0000'

To this format: 采用这种格式:

'08092017'

I am using dataweave. 我正在使用数据编织。 Here is my code: 这是我的代码:

order-date:payload.order.date_created 
as :localdatetime {format: "E, dd M yyyy hh:mm:ss Z"} 
as :string {format: "MMddyyyy"},

I still get the error - Cannot coerce a :string to a :localdatetime, caused by :Text 'Wed, 09 Aug 2017 20:16:59 +0000' could not be parsed at index 8 我仍然收到错误-无法将:string强制转换为:localdatetime,原因是:Text'Wed,2017 Aug 08 20:16:59 +0000'无法在索引8处解析

index 8 appears to the time zone offset, but according to java docs the timezone is specified as uppercase Z 索引8出现在时区偏移量上,但是根据Java文档,时区被指定为大写Z

If anyone stumbles across this from a google... I had the formatting incorrect. 如果有人从Google偶然发现此内容...我的格式不正确。 Here is the corrected version: 这是更正的版本:

order-date:payload.order.date_created 
as :localdatetime {format: "E, dd MMM yyyy HH:mm:ss Z"} 
as :string {format: "MMddyyyy"},

You should be able to easily do this using dataweave date formatting. 您应该能够使用dataweave日期格式轻松地做到这一点。 Here first you need to convert it to local datetime and then to date format you desire to convert to. 在这里,您首先需要将其转换为本地日期时间,然后再转换为您希望转换为的日期格式。 Giving some example of date format conversions from Mulesoft documentaions { dates : { date1: normalize("26-JUL-16") as :date {format: "d-MMM-yy"} as :string {format: "yyyy-MM-dd"}, date2: normalize("26/JUL/16") as :date {format: "d-MMM-yy"} as :string {format: "yyyy-MM-dd"}, date3: normalize("26.JUL.16") as :date {format: "d-MMM-yy"} as :string {format: "yyyy-MM-dd"} } } 提供一些来自Mulesoft文档的日期格式转换示例{date:{date1:​​normalize(“ 26-JUL-16”)as:date {format:“ d-MMM-yy”} as:string {format:“ yyyy-MM -dd“},date2:normalize(” 26 / JUL / 16“)as:date {format:” d-MMM-yy“} as:string {format:” yyyy-MM-dd“},date3:normalize( “ 26.JUL.16”)as:date {format:“ d-MMM-yy”} as:string {format:“ yyyy-MM-dd”}}}

Please read below links for more understanding of date formatting. 请阅读以下链接,以进一步了解日期格式。

https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-examples#parse-dates-with-different-separators 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-examples#parse-dates-with-different-separators 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