formatDateTime.php
Table of Contents
Functions
- formatDateTime() : string
- Formats a given date/time string into a specified format and timezone.
Functions
formatDateTime()
Formats a given date/time string into a specified format and timezone.
formatDateTime([string|null $date = null ][, string $timezone = 'UTC' ][, string|null $format = DateFormat::DEFAULT ]) : string
The $timezone parameter is used only to interpret the input date string, and
only when that string does not carry an offset of its own — 2025-07-20T09:30:00+02:00
says which moment it is, so PHP's own parser ignores $timezone for it.
The moment is then rendered in the timezone it was parsed in, except when
$format asks for a literal Z (an escaped \Z, as in the default format) : Z is
the ISO-8601 designator for UTC, so the moment is converted to UTC first and the
suffix tells the truth. A format carrying a real offset token (P, O, T) is left
in its own timezone, that token already saying which one it is.
Parameters
- $date : string|null = null
-
The input date/time string to format. If null, "now" is used.
- $timezone : string = 'UTC'
-
The timezone identifier (e.g., 'Europe/Paris'). Defaults to 'UTC'.
- $format : string|null = DateFormat::DEFAULT
-
The date format string compatible with DateTime::format(). If null, DateFormat::DEFAULT is used (ISO 8601 UTC with milliseconds).
Tags
Return values
string —The formatted date/time string.