Contact Us 1-800-596-4880

toTime

toTime(str: String, format: String | Null = null, locale: String | Null = null): Time

Transforms a String value into a Time 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 Time value.

format

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

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 toTime 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: toTime("23:57:59Z"),
   b: toTime("13:44:12.283-08:00","HH:mm:ss.nxxx")
}

Output

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