---
schema_version: "1"
id: 456f8e2165af6afdfc93e8603312a7499fdc0e8d6f60a1967f9726d955a67c15
title: toTime
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.12/dw-coercions-functions-totime.md
canonical_url: https://docs.mulesoft.com/dataweave/2.12/dw-coercions-functions-totime
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 91d58399a684644b55619019d9a9a6b7a2261f75f2adc9db16275bbf120f7a26
description: MuleSoft Documentation Site
release: "2.12"
latest: false
---
---
product: DataWeave
version: 2.12
---

# toTime

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## toTime(str: String, formatters: Array<Formatter>): Time

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

_Introduced in DataWeave version 2.5.0._

### Parameters

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Name</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p><code>str</code></p></td><td><p>String</p></td><td><p>The <code>String</code> value to transform into a <code>Time</code> value.</p></td></tr><tr><td><p><code>formatters</code></p></td><td><p>Array&lt;Formatter&gt;</p></td><td><p>The <code>array</code> of formatting to use on the <code>Time</code> value.</p></td></tr></tbody></table>

### Example

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

#### Source

```DataWeave
%dw 2.0
import * from dw::util::Coercions
import * from dw::Runtime
output application/dw
---
{
  a: toTime("13:44:12.283-08:00", [{format: "HH:mm:ss.xxx"}, {format: "HH:mm:ss.nxxx"}]),
  b: try(() -> toTime("13:44:12.283-08:00", [{format: "HH:mm:ss.xxx"}]).error.message
}
```

#### Output

```DataWeave
{
  a: |13:44:12.000000283-08:00| as Time {format: "HH:mm:ss.nxxx"},
  b: "Could not find a valid formatter for '13:44:12.283-08:00'"
}
```

## 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

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>str</code></p></td><td><p>The <code>String</code> value to transform into a <code>Time</code> value.</p></td></tr><tr><td><p><code>format</code></p></td><td><p>The formatting to use on the <code>Time</code> value. A <code>null</code> value has no effect on the <code>Time</code> value. This parameter accepts Java character patterns based on ISO-8601. A <code>Time</code> value, such as <code>10:15:30.000000</code>, has the format <code>HH:mm:ss.nxxx</code>.</p></td></tr><tr><td><p><code>locale</code></p></td><td><p>Optional ISO 3166 country code to use, such as <code>US</code>, <code>AR</code>, or <code>ES</code>. A <code>null</code> or absent value uses your JVM default.</p></td></tr></tbody></table>

### Example

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

#### Source

```DataWeave
%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

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