date_default_timezone_set
Sets the time zone for every date function.
Syntax
date_default_timezone_set(string $timezoneId): boolParameters
| Parameter | Type | Description |
|---|---|---|
| $timezoneId | string | The zone name: `Europe/Moscow`, `UTC`, `Asia/Tokyo`. |
Return value
bool`true` if the zone name is valid.
Examples
The same timestamp in different zones:
<?php
$timestamp = 1738245600;
date_default_timezone_set('UTC');
echo date('H:i', $timestamp), "\n";
date_default_timezone_set('Europe/Moscow');
echo date('H:i', $timestamp);Output:
14:00
17:00Notes
The zone is normally set once — in the date.timezone setting of php.ini or at the start of the program. Without it PHP uses UTC.
See also
Related recipes
In the tutorial
- Date and time — Working with dates in PHP — the date function, the DateTimeImmutable class, formats, adding to dates and the difference between them.