PHP date_default_timezone_get() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Date/Time

Definition

In PHP, date_default_timezone_get() returns the timezone identifier that PHP currently uses as its default, such as UTC or Asia/Kolkata.

Functions like date(), mktime() and strtotime(), and new DateTime objects without a timezone, all use this default timezone. The value comes from date_default_timezone_set() if you called it, otherwise from the date.timezone setting in php.ini, and finally it falls back to UTC.

Syntax

Call date_default_timezone_get() with the values you need. Start with this line.

PHP
$zone = date_default_timezone_get();
CallWhat it does
date_default_timezone_get()Returns the current default timezone, for example "UTC".
date_default_timezone_set('Asia/Kolkata'); date_default_timezone_get()Returns "Asia/Kolkata" after the timezone was changed.
(new DateTime('2024-01-15'))->getTimezone()->getName()A new DateTime without a timezone uses the same default timezone.

date_default_timezone_get() takes no arguments. If no timezone was set and date.timezone is empty or invalid, it returns UTC. Because the starting value depends on the server, set the timezone explicitly in your script when you need stable results.

Library declarations
PHP
date_default_timezone_get(): string

Parameters

ParameterDescription
—This function takes no parameters.

Return Value

Return ValueDescription
stringThe timezone identifier, such as UTC, Europe/Paris or America/New_York.

PHP Examples

Example 1 — Reading the Timezone After Setting It

Set a timezone first so the output is predictable, then read it back with date_default_timezone_get().

PHP
<?php
date_default_timezone_set('UTC');
echo date_default_timezone_get(), PHP_EOL;

date_default_timezone_set('Asia/Kolkata');
echo date_default_timezone_get(), PHP_EOL;

$ts = strtotime('2024-01-15 10:30:00 UTC');
echo date('Y-m-d H:i T', $ts), PHP_EOL;

How It Works

  1. After setting UTC, date_default_timezone_get() returns the string UTC.
  2. Setting Asia/Kolkata replaces the default, and the getter shows the new value.
  3. The timestamp is created from a UTC string, so it always means the same moment.
  4. date() uses the default timezone, so the moment prints as 16:00 IST.

Example 2 — A Failed Change Keeps the Old Value

If you try to set an invalid timezone name, the old timezone stays active. New DateTime objects also follow the default.

PHP
<?php
date_default_timezone_set('Europe/Paris');

$ok = @date_default_timezone_set('Mars/Base');
var_dump($ok);
echo date_default_timezone_get(), PHP_EOL;

$d = new DateTime('2024-01-15 10:30:00');
echo $d->getTimezone()->getName(), PHP_EOL;

How It Works

  1. The timezone is first set to Europe/Paris, which is a valid identifier.
  2. 'Mars/Base' is not a real timezone, so the setter returns false. The @ hides the notice PHP raises.
  3. The getter still returns Europe/Paris, because the failed call changed nothing.
  4. A DateTime created without a timezone picks up that same default.

Example 3 — Saving and Restoring the Timezone

Save the current timezone, switch to others for a moment, and then restore the original value.

PHP
<?php
$original = date_default_timezone_get();
$ts = strtotime('2024-01-15 10:30:00 UTC');

date_default_timezone_set('America/New_York');
echo date('Y-m-d H:i T', $ts), PHP_EOL;

date_default_timezone_set('Asia/Tokyo');
echo date('Y-m-d H:i T', $ts), PHP_EOL;

date_default_timezone_set($original);
echo date_default_timezone_get() === $original ? "Restored" : "Not restored", PHP_EOL;

How It Works

  1. The current timezone is saved in $original before any change is made.
  2. New York is five hours behind UTC in January, so 10:30 UTC prints as 05:30 EST.
  3. Tokyo is nine hours ahead of UTC, so the same moment prints as 19:30 JST.
  4. Setting $original puts the old timezone back, and the comparison confirms it.

Frequently Asked Questions

It returns the identifier of the timezone PHP uses by default, for example UTC or Europe/London. The value is a string.
PHP uses the date.timezone value from php.ini. If that is empty or invalid, it falls back to UTC.
Call date_default_timezone_set() with a valid identifier such as 'Asia/Kolkata', or set date.timezone in php.ini. The getter then returns the new value.
No. It takes no arguments and always returns a string.
date(), mktime(), strtotime(), idate(), getdate() and any DateTime or DateTimeImmutable created without a timezone all use it.

Next: date_default_timezone_set()

date_default_timezone_set() sets the default timezone used by all date and time functions .

date_default_timezone_set() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful