date_default_timezone_set()

date_default_timezone_set() — Sets the default timezone used by all date/time functions in a script.

Built-in function of PHP 8.5. The manual lists it as available in PHP 5 >= 5.1.0, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

date_default_timezone_set(string $timezoneId): bool

Parameters

ParameterTypeWhat it takes
$timezoneIdstringThe timezone identifier, like UTC, Africa/Lagos, Asia/Hong_Kong, or Europe/Lisbon. The list of valid identifiers is available in the List of Supported Timezones.

Return value

This function returns false if the timezoneId isn't valid, or true otherwise.

Example

A runnable snippet:

date_default_timezone_set('America/Los_Angeles'); $script_tz = date_default_timezone_get(); $ini_tz = ini_get('date.timezone'); if (strcmp($script_tz, $ini_tz)){ echo 'Script timezone differs from ini-set timezone.'; } else { echo 'Script timezone and ini-set timezone match.'; }

See also

date_default_timezone_get()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page date_default_timezone_set() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.