dateFormat a Unix timestamp
&reftitle.description;
stringdatestringformatintnulltimestamp&null;
Returns a string formatted according to the given format string using the
given integer timestamp (Unix timestamp) or the current time
if no timestamp is given. In other words, timestamp
is optional and defaults to the value of time.
Unix timestamps do not handle timezones. Use the
DateTimeImmutable class, and its
DateTimeInterface::format formatting method to
format date/time information with a timezone attached.
&reftitle.parameters;
format
Format accepted by DateTimeInterface::format.
date will always generate
000000 as microseconds since it takes an int
parameter, whereas DateTimeInterface::format does
support microseconds if an object of type
DateTimeInterface was created with microseconds.
&date.timestamp.description;
&reftitle.returnvalues;
Returns a formatted date string.
&reftitle.errors;
&date.timezone.errors.description;
&reftitle.changelog;
&Version;&Description;8.0.0timestamp is nullable now.
&reftitle.examples;
date examples
]]>
You can prevent a recognized character in the format string from being
expanded by escaping it with a preceding backslash. If the character with
a backslash is already a special sequence, you may need to also escape
the backslash.
Escaping characters in date
]]>
It is possible to use date and
mktime together to find dates in the future
or the past.
date and mktime example
]]>
This can be more reliable than simply adding or subtracting the number
of seconds in a day or month to a timestamp because of daylight saving
time.
Some examples of date formatting. Note that
you should escape any other characters, as any which currently
have a special meaning will produce undesirable results, and
other characters may be assigned meaning in future PHP versions.
When escaping, be sure to use single quotes to prevent characters
like \n from becoming newlines.
date Formatting
]]>
To format dates in other languages,
IntlDateFormatter::format
can be used instead of date.
&reftitle.notes;
To generate a timestamp from a string representation of the date, you
may be able to use strtotime. Additionally, some
databases have functions to convert their date formats into timestamps
(such as MySQL's UNIX_TIMESTAMP
function).
Timestamp of the start of the request is available in
$_SERVER['REQUEST_TIME'].
&reftitle.seealso;
DateTimeImmutable::__constructDateTimeInterface::formatgmdateidategetdategetlastmodmktimeIntlDateFormatter::formattimePredefined DateTime Constants