Example 1 — Offsets in Different Timezones
Create dates in two timezones and compare their offsets in seconds.
<?php
$kolkata = date_create("2024-01-15 12:00:00", timezone_open("Asia/Kolkata"));
$winter = date_create("2024-01-15 12:00:00", timezone_open("America/New_York"));
$summer = date_create("2024-07-15 12:00:00", timezone_open("America/New_York"));
echo date_offset_get($kolkata), PHP_EOL;
echo date_offset_get($winter), PHP_EOL;
echo date_offset_get($summer), PHP_EOL; How It Works
- timezone_open() creates a timezone, and date_create() uses it for each date.
- India is 5. 5 hours ahead of UTC, so the offset is +19800 seconds.
- New York in January is 5 hours behind UTC, which is -18000 seconds.
- In July New York uses daylight saving time, so the offset is -14400 seconds.

