Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP date_create() Function

PHP date_create() Function

PHP Date/Time PHP Date/Time Reference Manual

Example

Return a new DateTime object and then format the date:

Run Example »


Definition and Usage

The date_create() function returns a new DateTime object.

Syntax

date_create(

time,timezone);

Parameters Description
time Optional. Specifies a date/time string. NULL means the current date/time.
timezone Optional. Specifies the time time zone. Defaults to the current time zone.
 **提示:** [查看 PHP 中支持的所有时区列表](php-ref-timezones.html) |

Technical Details

Return Value: Returns a new DateTime object on success, or FALSE on failure.
PHP Version: 5.2+
Changelog: Since PHP 5.3+, an invalid date throws an exception.

More examples

Example 1

Return a new DateTime object with a given time zone, then format the date and time:

Run Example »


PHP Date/Time PHP Date/Time Reference Manual