PHP date_create () function
PHP Date / Time Reference Manual
Examples
It returns a new DateTime object, and then format the date:
<?php
$date=date_create("2013-03-15");
echo date_format($date,"Y/m/d");
?>
$date=date_create("2013-03-15");
echo date_format($date,"Y/m/d");
?>
Running instance »
Definition and Usage
date_create () function returns a new DateTime object.
grammar
date_create( time,timezone);
参数 | 描述 |
---|---|
time | 可选。规定一个日期/时间字符串。NULL 表示当前的日期/时间。 |
timezone | 可选。规定 time 的时区。默认是当前时区。 提示: 查看 PHP 中支持的所有时区列表 |
technical details
return value: | If successful, it returns a new DateTime object, if it fails it returns FALSE. |
---|---|
PHP version: | 5.2+ |
Update log: | Starting from PHP 5.3+, if the provisions of an illegal date will throw an exception. |
More examples
Example 1
Returns a new DateTime object with a given time zone, and then format the date and time:
<?php
$date=date_create("2013-03-15 23:40:00",timezone_open("Europe/Oslo"));
echo date_format($date,"Y/m/d H:iP");
?>
$date=date_create("2013-03-15 23:40:00",timezone_open("Europe/Oslo"));
echo date_format($date,"Y/m/d H:iP");
?>
Running instance »
PHP Date / Time Reference Manual