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.


Name Description


The String value to transform into a Time value.


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.


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


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


%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")


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

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub
Submit your feedback!
Share your thoughts to help us build the best documentation experience for you!
Take our latest survey!