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 = 'Y-m-dTH:i:s.vZ' ]) : string
This function attempts to validate and parse the input date string. If the input date is not valid according to the provided format, it defaults to the current date/time ("now"). It then applies the specified timezone and returns the formatted date string.
Parameters
- $date : string|null = null
-
The input date/time string to format. If null or invalid, "now" is used.
- $timezone : string = 'UTC'
-
The timezone identifier (e.g., 'Europe/Paris'). Defaults to 'UTC'.
- $format : string|null = 'Y-m-dTH:i:s.vZ'
-
The date format string compatible with DateTime::format(). Defaults to 'Y-m-d\TH:i:s.v\Z' (ISO 8601 UTC with milliseconds).
Tags
Return values
string —The formatted date/time string, or null if creation fails.