timezone_offset_get
Returns a time zone's offset from UTC, in seconds, for a specific date and time.
timezone_offset_get(DateTimeZone $object, DateTimeInterface $datetime): int- Added in PHP 5.2.0
Parameters
| Parameter | Type | Description |
|---|---|---|
$object | DateTimeZone | The time zone whose offset you want, e.g. from timezone_open() or new DateTimeZone(). |
$datetime | DateTimeInterface | The instant to compute the offset at. Which side of a daylight-saving transition this falls on decides the result. |
Return value
intThe offset from UTC in seconds; positive east of Greenwich, negative west.
Errors
Throws a TypeError if the arguments are not a DateTimeZone and a DateTimeInterface. There is no failure return value in PHP 8.
timezone_offset_get() is the procedural alias of DateTimeZone::getOffset(). It answers one question: how many seconds is this zone ahead of or behind UTC at that moment.
When to reach for it
Use it when you need the numeric offset rather than a formatted date: rendering "UTC+02:00" next to a zone name in a picker, sending an offset to a JavaScript client, or building a fixed offset string for a protocol that has no concept of named zones. It is also how you show users what the difference between two zones will be on a future date, which a naive "hours difference" calculation gets wrong across a transition.
What trips people up
The $datetime argument is not decoration. In a DST zone the answer changes twice a year, so Europe/Berlin returns 3600 in January and 7200 in July. Passing "now" while asking about a summer booking is the classic source of an hour-off bug. Also note that the zone attached to the DateTimeInterface you pass is irrelevant — only the instant it represents matters.
The return value is seconds, not hours. Divide by 3600 for hours, and remember that some zones are not on a whole-hour boundary: India is 19800 and Nepal is 20700, so integer hour arithmetic loses the minutes.
Example
When to use it
- Display "UTC+05:45" beside a zone name in a settings dropdown
- Send a client the correct offset for a meeting date months in the future
- Convert a stored named zone into a fixed offset for a protocol that only accepts one
Frequently asked questions
Is the return value in hours or seconds?
Seconds. Divide by 3600 for hours, but keep the remainder because zones such as Asia/Kolkata and Asia/Kathmandu are offset by 30 or 45 minutes.
Why does the same zone give two different offsets?
Daylight saving time. The offset is computed for the instant you pass, so a summer date and a winter date legitimately differ by an hour.
What is the difference between timezone_offset_get and DateTimeZone::getOffset?
None in behaviour - timezone_offset_get is the procedural alias of the method. Use whichever style the surrounding code already uses.
More examples
Formatting an offset as +HH:MM
Handling the sign separately keeps intdiv from truncating toward zero incorrectly on negative values. The output reads UTC+01:00, UTC+05:30 and UTC-06:00 for that August instant.
<?php
$when = new DateTimeImmutable('2025-08-01 09:00', new DateTimeZone('UTC'));
foreach (['Europe/Lisbon', 'Asia/Kolkata', 'America/Denver'] as $name) {
$offset = timezone_offset_get(new DateTimeZone($name), $when);
$sign = $offset < 0 ? '-' : '+';
$abs = abs($offset);
printf("%-16s UTC%s%02d:%02d\n", $name, $sign, intdiv($abs, 3600), intdiv($abs % 3600, 60));
}The difference between two zones on a given date
The gap is 16 hours in January and 14 in July, because the two hemispheres switch DST in opposite directions. A hard-coded constant difference would be wrong for half the year.
<?php
$ny = new DateTimeZone('America/New_York');
$syd = new DateTimeZone('Australia/Sydney');
foreach (['2025-01-10', '2025-07-10'] as $day) {
$at = new DateTimeImmutable($day . ' 12:00', new DateTimeZone('UTC'));
$diff = (timezone_offset_get($syd, $at) - timezone_offset_get($ny, $at)) / 3600;
echo "$day: Sydney is $diff hours ahead of New York\n";
}
Discussion