PHP timezone_offset_get() Function

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

Definition

In PHP, timezone_offset_get() returns the offset from UTC, in seconds, for a time zone at a specific date and time.

The offset depends on the date because of daylight saving time. New York is five hours behind UTC in winter and four hours behind in summer, so you must say which moment you mean. It is the procedural version of DateTimeZone::getOffset().

Syntax

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

PHP
$seconds = timezone_offset_get($tz, $date);
CallWhat it does
timezone_offset_get($tz, new DateTime('2026-01-01'))Returns the offset of the zone on January 1, 2026.
timezone_offset_get($tz, new DateTime('now'))Returns the offset at the current moment.
$tz->getOffset($date)The object-oriented version that returns the same number.

A positive number means the zone is ahead of UTC, and a negative number means it is behind. Divide by 3600 to convert seconds into hours.

Library declarations
PHP
timezone_offset_get(DateTimeZone $object, DateTimeInterface $datetime): int

Parameters

ParameterDescription
objectRequired. A DateTimeZone object, usually created with timezone_open() or new DateTimeZone().
datetimeRequired. A DateTime or DateTimeImmutable object that sets the moment used to find the offset. Only the point in time matters, not the time zone stored in that object.

Return Value

Return ValueDescription
intThe offset from UTC in seconds, including any daylight saving adjustment.

PHP Examples

Example 1 — Offset of a Fixed Zone

India does not use daylight saving time, so its offset is always the same. We use a fixed date so the output never changes.

PHP
<?php
$tz = new DateTimeZone('Asia/Kolkata');
$date = new DateTime('2026-01-01 12:00:00');

$seconds = timezone_offset_get($tz, $date);

echo $seconds, PHP_EOL;
echo $seconds / 3600, " hours", PHP_EOL;

How It Works

  1. The DateTimeZone object is for Asia/Kolkata.
  2. The DateTime object gives the moment to look at.
  3. timezone_offset_get() returns 19800 seconds, which is 5 hours and 30 minutes ahead of UTC.
  4. Dividing by 3600 turns the seconds into hours.

Example 2 — Daylight Saving Time Changes the Offset

New York uses a different offset in winter and in summer. The same zone gives two different answers for two dates.

PHP
<?php
$tz = new DateTimeZone('America/New_York');

$winter = new DateTime('2026-01-15 12:00:00');
$summer = new DateTime('2026-07-15 12:00:00');

echo "Winter: ", timezone_offset_get($tz, $winter), PHP_EOL;
echo "Summer: ", timezone_offset_get($tz, $summer), PHP_EOL;

How It Works

  1. The same DateTimeZone object is used for both calls.
  2. In January New York is on standard time, five hours behind UTC, which is -18000 seconds.
  3. In July daylight saving time is active, so it is four hours behind, which is -14400 seconds.
  4. The date you pass decides which offset is returned.

Example 3 — Formatting the Offset as +HH:MM

Turn the number of seconds into a readable offset like +09:00 for a few zones.

PHP
<?php
$date = new DateTime('2026-01-01 00:00:00');
$zones = ['Asia/Tokyo', 'Asia/Kolkata', 'UTC'];

foreach ($zones as $zone) {
    $o = timezone_offset_get(timezone_open($zone), $date);
    $text = sprintf('%+03d:%02d', intdiv($o, 3600), intdiv(abs($o) % 3600, 60));
    echo $zone, ' ', $text, PHP_EOL;
}

How It Works

  1. The loop visits each zone name and creates a DateTimeZone with timezone_open().
  2. timezone_offset_get() returns the offset in seconds for the fixed date.
  3. intdiv($o, 3600) gives the whole hours, and the modulo part gives the remaining minutes.
  4. sprintf() with %+03d adds a plus sign and pads the hours with a zero.

Frequently Asked Questions

It returns the number of seconds a time zone is ahead of (positive) or behind (negative) UTC at a given moment.
Because the offset can change during the year. Daylight saving time moves the clock, so the same zone has different offsets in winter and summer.
Divide the number of seconds by 3600. For example, 19800 / 3600 is 5.5 hours.
Yes. It is the procedural alias of the getOffset() method.
timezone_offset_get() asks a DateTimeZone for its offset at a given date. date_offset_get() reads the offset already stored inside a DateTime object.

Next: timezone_open()

timezone_open() creates a DateTimeZone object from a time zone name, an offset or an abbre.

timezone_open() 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