The date_default_timezone_set() function is a built-in function in PHP that is used to set the default time zone used by all date/time functions in the script. This function returns False if the time zone is invalid, True otherwise.
How to use php date_default_timezone_set() function?
php date_default_timezone_set() function sets the default time zone used by all date/time functions in the script.
Syntax:
date_default_timezone_set(timezone);
Parameters: This function accepts a single required parameter
● timezone: required. Set the time zone identifier, specifying the time zone to use, such as "UTC" or "Europe/Paris".
Return value: If timezone_identifier is invalid, this function returns False, otherwise it returns True.
Let’s take a look at how to use the php date_default_timezone_set() function through an example.
Example
<?php date_default_timezone_set("Asia/Beijing"); echo date_default_timezone_get(); ?>
Output:
Asia/Shanghai
The above is the detailed content of How to use php date_default_timezone_set function. For more information, please follow other related articles on the PHP Chinese website!