Contact Us 1-800-596-4880

toLocalTime

toLocalTime(str: String, formatters: Array<Formatter>): LocalTime

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

Introduced in DataWeave version 2.5.0.

Parameters

Name Type Description

str

String

The String value to transform into a LocalTime value.

formatters

Array<Formatter>

The array of formatting to use on the LocalTime value.

Example

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

Source

%dw 2.0
import * from dw::util::Coercions
import * from dw::Runtime
output application/dw
---
{
  a: toLocalTime("23:57:59", [{format: "HH:mm:ss.n"}, {format: "HH:mm:ss"}]),
  b: try(() -> toLocalTime("23:57:59", [{format: "HH:mm:ss.n"}])).error.message
}

Output

{
  a: |23:57:59| as LocalTime {format: "HH:mm:ss"},
  b: "Could not find a valid formatter for '23:57:59'"
}

toLocalTime(str: String, format: String | Null = null, locale: String | Null = null): LocalTime

Transforms a String value into a LocalTime value and accepts a format and locale.

Introduced in DataWeave version 2.4.0.

Parameters

Name Description

str

The String value to transform into a LocalTime value.

format

The formatting to use on the LocalTime value. A null value has no effect on the LocalTime value. This parameter accepts Java character patterns based on ISO-8601. A LocalTime value, such as 22:15:30.000000, has the format HH:mm:ss.n.

locale

Optional ISO 3166 country code to use, such as US, AR, or ES. A null or absent value uses your JVM default.

Example

This example shows how toLocalTime behaves with different inputs.

Source

%dw 2.0
import * from dw::util::Coercions
output application/json
---
{
   toLocalTimeEx: toLocalTime("23:57:59"),
   toLocalTimeEx2: toLocalTime("13:44:12.283","HH:mm:ss.n")
}

Output

{
  "toLocalTimeEx": "23:57:59",
  "toLocalTimeEx2": "13:44:12.283"
}