如何处理 Mule 4 中的缩写年份模式 (yy)

How to handle abbreviated year pattern (yy) in Mule 4

输入:

{
  "date": "01-JAN-70"
}

预期输出:

{
  "date": "1970-01-01"
}

感谢您的意见

试试这个方法:

%dw 2.0
output application/json
var year = "19" ++ (payload.date splitBy "-")[2]
var fDate = ((payload.date splitBy "-")[0] ++ "-" ++ (payload.date splitBy "-")[1] ++ "-" ++ year) 
---
fDate as Date {"format": "dd-MMM-yyyy"} as String {"format": "uuuu-MM-dd"}

这是一个不使用字符串操作的答案,这不是处理日期的好习惯。函数 replaceCentury() 让您用另一个日期替换世纪。

%dw 2.0
output application/json
import * from dw::core::Dates
fun centuryFromYear(c)=floor( (c / 100)) * 100
// replaceCentury(): d is the input date, c is the century that you want the date to be in
fun replaceCentury(d: Date, c: Number)= date({year: d.year - centuryFromYear(d.year) + c, month: d.month, day: d.day})
var inputDate=payload.date as Date {format: "dd-MMM-yy"} 
---
replaceCentury(inputDate, 1900)

输出:

"1970-01-01"