PHP date_default_timezone_set() Function

Example

Set Default Timezone:

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

Running Example

Definition and Usage

The date_default_timezone_set() function sets the default timezone for all date/time functions in the script.

Syntax

date_default_timezone_set(timezone);
Parameter Description
timezone

Required. Specify the timezone to use, such as "UTC" or "Europe/Paris".

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

Technical Details

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

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

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