---
schema_version: "1"
id: 4006d2372484aa03537f569f76616a1c839ba9f3a196bb014c07b16494460e30
title: toDateTime
collection: mulesoft
version: current
locale: ja-jp
portal_url: https://docs.salesforce.com/mulesoft/current/ja-jp/dataweave/2.8/dw-coercions-functions-todatetime.md
canonical_url: https://docs.mulesoft.com/jp/dataweave/2.8/dw-coercions-functions-todatetime
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 3eae26f98cfee64a13638aa4f0fcba0c6165c11f3d0106bba6d14ab31bcb9b43
description: MuleSoft Documentation Site
release: "2.8"
latest: false
---
# toDateTime

## [](#todatetime1)toDateTime(str: String, formatters: Array<Formatter>): DateTime

変換する特定の値と一致する最初の ​`Formatter`​ を使用して、​`String`​ 値を ​`DateTime`​ 値に変換します。

_DataWeave バージョン 2.5.0 で導入されました。_

### [](#パラメーター)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 20%;">
<col style="width: 20%;">
<col style="width: 60%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">型</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>str</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">String (文字列)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DateTime</code>​ 値に変換する ​<code>String</code>​ 値。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>formatters</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Array&lt;Formatter&gt;</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DateTime</code>​ 値に対して使用する書式設定の ​<code>array</code>​。</p></td>
</tr>
</tbody>
</table>

### [](#例)例

次の例では、さまざまな入力での ​`toDateTime`​ の動作を示します。 `application/dw`​ 形式の出力が生成されます。

#### [](#ソース)ソース

```DataWeave
%dw 2.0
import * from dw::util::Coercions
import * from dw::Runtime
output application/dw
---
{
  a: toDateTime("2003-10-01 23:57:59Z", [{format: "uuuu/MM/dd HH:mm:ssz"}, {format: "uuuu-MM-dd HH:mm:ssz"}]),
  b: try(() -> toDateTime("2003-10-01 23:57:59Z", [{format: "uuuu/MM/dd HH:mm:ssz"}])).error.message
}
```

#### [](#出力)出力

```DataWeave
{
  a: |2003-10-01T23:57:59Z| as DateTime {format: "uuuu-MM-dd HH:mm:ssz"},
  b: "Could not find a valid formatter for '2003-10-01 23:57:59Z'"
}
```

## [](#todatetime2)toDateTime(number: Number, unit: MillisOrSecs | Null = null): DateTime

`milliseconds`​ または ​`seconds`​ を単位として使用して ​`Number`​ 値を ​`DateTime`​ 値に変換します。

_DataWeave バージョン 2.4.0 で導入されました。_

### [](#パラメーター-2)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>number</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DateTime</code>​ 値に変換する ​<code>Number</code>​ 値。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>unit</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">変換に使用する単位: <code>"milliseconds"</code>​ または ​<code>"seconds"</code>​。​<code>unit</code>​ 項目の ​<code>null</code>​ 値のデフォルトは ​<code>"seconds"</code>​ です。</p></td>
</tr>
</tbody>
</table>

### [](#例-2)例

次の例では、さまざまな入力での ​`toDateTime`​ の動作を示します。 `application/dw`​ 形式の出力が生成されます。

#### [](#ソース-2)ソース

```DataWeave
%dw 2.0
import * from dw::util::Coercions
output application/dw
---
{
    fromEpoch: toDateTime(1443743879),
    fromMillis: toDateTime(1443743879000, "milliseconds")
}
```

#### [](#出力-2)出力

```DataWeave
{
  fromEpoch: |2015-10-01T23:57:59Z|,
  fromMillis: |2015-10-01T23:57:59Z| as DateTime {unit: "milliseconds"}
}
```

## [](#todatetime3)toDateTime(str: String, format: String | Null = null, locale: String | Null = null): DateTime

`String`​ 値を ​`DateTime`​ 値に変換して、形式とロケールを受け入れます。

_DataWeave バージョン 2.4.0 で導入されました。_

### [](#パラメーター-3)パラメーター

<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 25%;">
<col style="width: 75%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">名前</th>
<th class="tableblock halign-left valign-top">説明</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>str</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DateTime</code>​ 値に変換する ​<code>String</code>​ 値。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>format</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>DateTime</code>​ 値に対して使用する書式設定。
           ​<code>null</code>​ 値は ​<code>DateTime</code>​ 値に対して無効です。
           このパラメーターでは、ISO-8601 に基づいた Java 文字パターンを受け入れます。​<code>2011-12-03T10:15:30.000000+01:00</code>​ などの ​<code>DateTime</code>​ 値の形式は ​<code>uuuu-MM-dd HH:mm:ssz</code>​ となります。</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>locale</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">使用する省略可能な ISO 3166 国コード (​<code>US</code>​、​<code>AR</code>​、​<code>ES</code>​ など)。​<code>null</code>​ または欠落値では JVM のデフォルトが使用されます。</p></td>
</tr>
</tbody>
</table>

### [](#例-3)例

次の例では、さまざまな入力での ​`toDateTime`​ の動作を示します。 `application/dw`​ 形式の出力が生成されます。

#### [](#ソース-3)ソース

```DataWeave
%dw 2.0
import * from dw::util::Coercions
output application/dw
---
{
   a: toDateTime("2015-10-01T23:57:59Z"),
   b: toDateTime("2003-10-01 23:57:59Z","uuuu-MM-dd HH:mm:ssz")
}
```

#### [](#出力-3)出力

```DataWeave
{
  a: |2015-10-01T23:57:59Z|,
  b: |2003-10-01T23:57:59Z| as DateTime {format: "uuuu-MM-dd HH:mm:ssz"}
}
```