%dw 2.0
import * from dw::util::Coercions
import * from dw::Runtime
output application/dw
---
{
  a: toDateTime("2003-10-01 23:57:59Z", [{format: "uuuu/MM/dd HH:mm:ssz"}, {format: "uuuu-MM-dd HH:mm:ssz"}]),
  b: try(() -> toDateTime("2003-10-01 23:57:59Z", [{format: "uuuu/MM/dd HH:mm:ssz"}])).error.message
}
toDateTime
toDateTime(str: String, formatters: Array<Formatter>): DateTime
Transforms a String value into a DateTime value using the first Formatter that
matches with the given value to transform.
Introduced in DataWeave version 2.5.0.
Parameters
| Name | Type | Description | 
|---|---|---|
  | 
String  | 
The   | 
  | 
Array<Formatter>  | 
The   | 
Example
This example shows how toDateTime behaves with different inputs.
It produces output in the application/dw format.
Source
toDateTime(number: Number, unit: MillisOrSecs | Null = null): DateTime
Transforms a Number value into a DateTime value
using milliseconds or seconds as the unit.
Introduced in DataWeave version 2.4.0.
Parameters
| Name | Description | 
|---|---|
  | 
The   | 
  | 
The unit to use for the conversion:   | 
toDateTime(str: String, format: String | Null = null, locale: String | Null = null): DateTime
Transforms a String value into a DateTime value
and accepts a format and locale.
Introduced in DataWeave version 2.4.0.
Parameters
| Name | Description | 
|---|---|
  | 
The   | 
  | 
The formatting to use on the   | 
  | 
Optional ISO 3166 country code to use, such as   | 
Example
This example shows how toDateTime behaves with different inputs.
It produces output in the application/dw format.



