Contact Us 1-800-596-4880

toTimeOrNull

toTimeOrNull(str: String, formatters: Array<Formatter>): Time | Null

Transforms a String value into a Time value using the first Formatter that matches with the given value to transform.

If none of the Formatter matches with the given value, the function returns a null value.

Introduced in DataWeave version 2.5.0.

Parameters

Name Type Description

str

String

The String value to transform into a Time value.

formatters

Array<Formatter>

The array of formatting to use on the Time value.

Example

This example shows how toTimeOrNull behaves with different inputs. It produces output in the application/dw format.

Source

%dw 2.0
import * from dw::util::Coercions
output application/dw
---
{
  a: toTimeOrNull("13:44:12.283-08:00", [{format: "HH:mm:ss.xxx"}, {format: "HH:mm:ss.nxxx"}]),
  b: toTimeOrNull("13:44:12.283-08:00", [{format: "HH:mm:ss.xxx"}])
}

Output

{
  a: |13:44:12.000000283-08:00| as Time {format: "HH:mm:ss.nxxx"},
  b: null
}