Copyright © tutorialspoint.com
|
DateTime date_create ( [$time [, timezone]] ); DateTime DateTime::__construct ( [$time [, $timezone]] ); |
These functions return new DateTime object.
The above two functions are equivalent and any of the functions can be used as shown below in the example.
| Parameter | Description |
|---|---|
| time | Optional. String in a format accepted by strtotime(), defaults to "now". |
| timezone | Optional. Time zone of the time. |
Returns DateTime object on success or FALSE on failure.
Following is the usage of this function:
<?php
$dateSrc = '2007-04-19 12:50 GMT';
$dateTime = new DateTime($dateSrc);
echo 'DateTime::format(): '.$dateTime->format('H:i:s');
echo "\n";
$dateSrc = '2007-04-19 12:50 GMT';
$dateTime = date_create($dateSrc);
echo 'DateTime::format(): '.$dateTime->format('H:i:s');
?>
|
This will produce following result:
DateTime::format(): 12:50:00 DateTime::format(): 12:50:00 |
Copyright © tutorialspoint.com