0

我的输入是一个.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
4

1 回答 1

1

使用日期格式转换为日期格式,然后使用第二种日期格式转换回字符串:

varOutput: 'Aug-03-2015'  as :date {format : "MMM-dd-yyyy"} as :string {format: "dd/MM/yyyy"}
于 2015-12-10T11:34:35.097 回答