PHP date_default_timezone_set() Function: Description, Parameters, Return Value, and Example
This article explains the PHP date_default_timezone_set() function, detailing its purpose of setting a default timezone for all date/time functions, the required timezone identifier parameter, the boolean return values, and provides a practical code example with expected output.
The date_default_timezone_set() function in PHP sets the default timezone used by all date and time functions within a script.
Signature: bool date_default_timezone_set(string $timezone_identifier)
Parameter: $timezone_identifier – a timezone identifier such as UTC or Europe/Lisbon .
Return value: Returns TRUE on success; returns FALSE if the provided identifier is invalid.
Example usage:
<?php
date_default_timezone_set('America/Los_Angeles');
$script_tz = date_default_timezone_get();
if (strcmp($script_tz, ini_get('date.timezone'))){
echo 'Script timezone differs from ini-set timezone.';
} else {
echo 'Script timezone and ini-set timezone match.';
}
?>The script sets the timezone to America/Los_Angeles , retrieves the current script timezone, compares it with the timezone defined in php.ini , and outputs a message indicating whether they match.
Sample output: Script timezone differs from ini-set timezone.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.