Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

date_default_timezone_set

Sets the time zone for every date function.

Syntax

date_default_timezone_set(string $timezoneId): bool

Parameters

ParameterTypeDescription
$timezoneIdstringThe 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:00

Notes

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

  • date — Formats a date and time.
  • time — Returns the current timestamp.

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.

Thanks for reading!

Donate to the site — we work hard for you.