Dataweave 中的字符串转换到日期
String conversion to date in Dataweave
我的输入是一个 .csv
格式文件,其中包含
等字符串的出生日期列
Aug-03-2015
我想将此列更改为日期(如果不可能,至少更改为另一个字符串)格式如下
03-08-2015
。
尝试了 RyanCarter 建议的逻辑。我现在已经尝试使用
Birthday:$.DOB as :date {format : "MMM-dd-yyyy"} as :string {format: "dd/MM/yyyy"}
其中 DOB 是 .csv 输入中的字符串列。但是我遇到了以下异常。
Message : Exception while executing:
DOB:$.DOB as :date {format : "MMM-dd-yyyy"} as :string {format: "dd/MM/yyyy"}
^
Cannot coerce a :string to a :date, caused by :Text 'NOV-03-1992' could not be parsed at index 0
Type : com.mulesoft.weave.mule.exception.WeaveExecutionException
Code : MULE_ERROR--2
********************************************************************************
Exception stack is:
1. Cannot coerce a :string to a :date, caused by :Text 'NOV-03-1992' could not be parsed at index 0
(com.mulesoft.weave.model.values.coercion.exception.UnsupportedTypeCoercionException)
com.mulesoft.weave.model.values.coercion.LocalDateTypeCoercionValue:30 (null)
2. Exception while executing:
DOB:$.DOB as :date {format : "MMM-dd-yyyy"} as :string {format: "dd/MM/yyyy"}
^
Cannot coerce a :string to a :date, caused by :Text 'NOV-03-1992' could not be parsed at index 0 (com.mulesoft.weave.mule.exception.WeaveExecutionException)
com.mulesoft.weave.mule.WeaveMessageProcessor$WeaveOutputHandler:166 (null)
********************************************************************************
Root Exception stack trace:
com.mulesoft.weave.model.values.coercion.exception.UnsupportedTypeCoercionException: Cannot coerce a :string to a :date, caused by :Text 'NOV-03-1992' could not be parsed at index 0
首先使用日期格式转换为日期,然后使用第二种日期格式转换回字符串:
varOutput: 'Aug-03-2015' as :date {format : "MMM-dd-yyyy"} as :string {format: "dd/MM/yyyy"}
我的输入是一个 .csv
格式文件,其中包含
Aug-03-2015
我想将此列更改为日期(如果不可能,至少更改为另一个字符串)格式如下
03-08-2015
。 尝试了 RyanCarter 建议的逻辑。我现在已经尝试使用
Birthday:$.DOB as :date {format : "MMM-dd-yyyy"} as :string {format: "dd/MM/yyyy"}
其中 DOB 是 .csv 输入中的字符串列。但是我遇到了以下异常。
Message : Exception while executing:
DOB:$.DOB as :date {format : "MMM-dd-yyyy"} as :string {format: "dd/MM/yyyy"}
^
Cannot coerce a :string to a :date, caused by :Text 'NOV-03-1992' could not be parsed at index 0
Type : com.mulesoft.weave.mule.exception.WeaveExecutionException
Code : MULE_ERROR--2
********************************************************************************
Exception stack is:
1. Cannot coerce a :string to a :date, caused by :Text 'NOV-03-1992' could not be parsed at index 0
(com.mulesoft.weave.model.values.coercion.exception.UnsupportedTypeCoercionException)
com.mulesoft.weave.model.values.coercion.LocalDateTypeCoercionValue:30 (null)
2. Exception while executing:
DOB:$.DOB as :date {format : "MMM-dd-yyyy"} as :string {format: "dd/MM/yyyy"}
^
Cannot coerce a :string to a :date, caused by :Text 'NOV-03-1992' could not be parsed at index 0 (com.mulesoft.weave.mule.exception.WeaveExecutionException)
com.mulesoft.weave.mule.WeaveMessageProcessor$WeaveOutputHandler:166 (null)
********************************************************************************
Root Exception stack trace:
com.mulesoft.weave.model.values.coercion.exception.UnsupportedTypeCoercionException: Cannot coerce a :string to a :date, caused by :Text 'NOV-03-1992' could not be parsed at index 0
首先使用日期格式转换为日期,然后使用第二种日期格式转换回字符串:
varOutput: 'Aug-03-2015' as :date {format : "MMM-dd-yyyy"} as :string {format: "dd/MM/yyyy"}