DateTime::createFromInterface

(PHP 8)

DateTime::createFromInterface指定された DateTimeInterface オブジェクトをカプセル化した、新しい DateTime オブジェクトを返す

説明

publicstaticDateTime::createFromInterface(DateTimeInterface$object): DateTime

パラメータ

object

変更可能なバージョンに変換する DateTimeInterface オブジェクト。 このオブジェクトは変更されませんが、 同じ日付、時刻、タイムゾーンの情報が入った新しい DateTime オブジェクトが作成されます。

戻り値

新しいDateTime クラスのインスタンスを返します。

例1 変更可能な DateTime オブジェクトを作る

<?php
$date
= new DateTimeImmutable("2014-06-20 11:45 Europe/London");

$mutable = DateTime::createFromInterface($date);

$date = new DateTime("2014-06-20 11:45 Europe/London");
$also_mutable = DateTime::createFromInterface($date);
?>
To Top