array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'it', ), 'this' => array ( 0 => 'datetimeimmutable.createfrominterface.php', 1 => 'DateTimeImmutable::createFromInterface', 2 => 'Returns new DateTimeImmutable object encapsulating the given DateTimeInterface object', ), 'up' => array ( 0 => 'class.datetimeimmutable.php', 1 => 'DateTimeImmutable', ), 'prev' => array ( 0 => 'datetimeimmutable.createfromformat.php', 1 => 'DateTimeImmutable::createFromFormat', ), 'next' => array ( 0 => 'datetimeimmutable.createfrommutable.php', 1 => 'DateTimeImmutable::createFromMutable', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/datetime/datetimeimmutable/createfrominterface.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

DateTimeImmutable::createFromInterface

(PHP 8)

DateTimeImmutable::createFromInterfaceReturns new DateTimeImmutable object encapsulating the given DateTimeInterface object

Descrizione

public static DateTimeImmutable::createFromInterface(DateTimeInterface $object): DateTimeImmutable

Elenco dei parametri

object

The DateTimeInterface object that needs to be converted to an immutable version. This object is not modified, but instead a new DateTimeImmutable object is created containing the same date, time, and timezone information.

Valori restituiti

Returns a new DateTimeImmutable instance.

Esempi

Example #1 Creating an immutable date time object

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

$immutable = DateTimeImmutable::createFromInterface($date);

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