Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

date_create

Description

The date_create of Date / Time for PHP returns new DateTime object.

Syntax

date_create ([ string $datetime = "now" [, DateTimeZone $timezone = NULL ]] ) : DateTime

Parameters

datetime

A date/time string. Valid formats are explained in Date and Time Formats. Enter "now" here to obtain the current time when using the $timezone parameter.

timezone

A DateTimeZone object representing the timezone of $datetime. If $timezone is omitted, the current timezone will be used. Note: The $timezone parameter and the current timezone are ignored when the $datetime parameter either is a UNIX timestamp (e.g. @946684800) or specifies a timezone (e.g. 2010-01-28T15:00:00+02:00).

Return

Returns a new DateTime instance. Procedural style returns FALSE on failure.

Examples

1 · void

<?

$return = date_create();

echo date_format($return, "Y-m-d H:i:s");

?>
2024-09-20 06:20:10

2 · datetime

<?

$datetime = "2001-01-01";

$return = date_create($datetime);

echo date_format($return, "Y-m-d H:i:s");

?>
2001-01-01 00:00:00

3 · timezone

<?

$datetime = "now";
$timezone = timezone_open("America/New_York");

$return = date_create($datetime, $timezone);

echo date_format($return, "Y-m-d H:i:s");

?>
2024-09-20 02:20:11
HomeMenu