PHP DateTime - createFromInterface() Method
The PHP DateTime::createFromInterface() method returns a new DateTime object encapsulating the given DateTimeInterface object.
Syntax
public DateTime::createFromInterface(object)
Parameters
object |
Required. Specify the DateTimeInterface object that needs to be converted to a mutable version. This object is not modified, but instead a new DateTime object is created containing the same date, time, and timezone information. |
Return Value
Returns a new DateTime instance.
Example: creating a mutable date time objects
The example below shows the usage of DateTime::createFromInterface() method.
<?php $date1 = new DateTime("10-Mar-2015 5:10:25 Europe/London"); $date2 = new DateTimeImmutable("25-Oct-2015 5:10:25 Europe/London"); //creating mutable date time objects using interface $mutable1 = DateTime::createFromInterface($date1); $mutable2 = DateTime::createFromInterface($date2); //displaying the result echo $date1->format('d-M-Y H:i:s P')."\n"; echo $mutable1->format('d-M-Y H:i:s P')."\n"; echo "\n"; echo $date2->format('d-M-Y H:i:s P')."\n"; echo $mutable2->format('d-M-Y H:i:s P')."\n"; ?>
The output of the above code will be:
10-Mar-2015 05:10:25 +00:00 10-Mar-2015 05:10:25 +00:00 25-Oct-2015 05:10:25 +00:00 25-Oct-2015 05:10:25 +00:00
❮ PHP Date and Time Reference