---
schema_version: "1"
id: c51277a43be30af370aa00bd2b91ba2ee44eada54a95428d79a61571960c4ea8
title: toLocalTime
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.11/dw-coercions-functions-tolocaltime.md
canonical_url: https://docs.mulesoft.com/dataweave/2.11/dw-coercions-functions-tolocaltime
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 0b5ed53e01bdb5840522dc8541a452bec8490d3a6da945ab397021d94d428e0c
description: MuleSoft Documentation Site
release: "2.11"
latest: false
---
---
product: DataWeave
version: 2.11
---

# toLocalTime

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

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

<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>LocalTime</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>LocalTime</code> value.</p></td></tr></tbody></table>

### Example

This example shows how `toLocalTime` 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: 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

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

<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>LocalTime</code> value.</p></td></tr><tr><td><p><code>format</code></p></td><td><p>The formatting to use on the <code>LocalTime</code> value. A <code>null</code> value has no effect on the <code>LocalTime</code> value. This parameter accepts Java character patterns based on ISO-8601. A <code>LocalTime</code> value, such as <code>22:15:30.000000</code>, has the format <code>HH:mm:ss.n</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 `toLocalTime` behaves with different inputs.

#### Source

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

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