PHP date_default_timezone_set() Function

Example

Set Default Time Zone:

<?php
date_default_timezone_set("Asia/Shanghai");
echo date_default_timezone_get();
?>

Running Instance

Definition and Usage

The 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 Description
timezone

Required. Specify the time zone to be used, such as "UTC" or "Europe/Paris".

List of valid time zones: http://www.php.net/manual/zh/timezones.php

Technical Details

Return Value: If timezone If invalid, it returns FALSE, otherwise it returns TRUE.
PHP Version: 5.1+
Update Log:

Starting from PHP 5.1.2+, the function begins to validate timezone Parameters.

Starting from PHP 5.3+, it throws E_WARNING instead of E_STRICT.