date
Table of Contents
Functions
- formatDateTime() : string
- Formats a given date/time string into a specified format and timezone.
- isDate() : bool
- Indicates if the passed-in expression is a valid date with a specific format (default 'Y-m-d').
- isValidTimezone() : bool
- Indicates if the passed-in expression is a valid timezone.
Functions
formatDateTime()
Formats a given date/time string into a specified format and timezone.
formatDateTime([string|null $date = null ][, string|null $timezone = 'Europe/Paris' ][, string|null $format = 'Y-m-dTH:i:s' ]) : 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|null = 'Europe/Paris'
-
The timezone identifier (e.g., 'Europe/Paris'). Defaults to 'Europe/Paris'.
- $format : string|null = 'Y-m-dTH:i:s'
-
The date format string compatible with DateTime::format(). Defaults to 'Y-m-d\TH:i:s'.
Tags
Return values
string —The formatted date/time string, or null if creation fails.
isDate()
Indicates if the passed-in expression is a valid date with a specific format (default 'Y-m-d').
isDate(string|null $date[, string $format = 'Y-m-d' ]) : bool
Parameters
- $date : string|null
-
The expression to evaluate.
- $format : string = 'Y-m-d'
-
The date format (default 'Y-m-d').
Tags
Return values
bool —Indicates if the passed-in expression is a valid timezone.
isValidTimezone()
Indicates if the passed-in expression is a valid timezone.
isValidTimezone([string|null $timezone = null ]) : bool
Note: timezone_identifiers_list() requires PHP >= 5.2
Parameters
- $timezone : string|null = null
-
The timezone expression to evaluates.
Tags
Return values
bool —Indicates if the passed-in expression is a valid timezone.