Example 1 — Read the Timezone Name
Create a date in India and ask which timezone it uses.
<?php
$date = date_create("2024-01-15 12:00:00", timezone_open("Asia/Kolkata"));
$tz = date_timezone_get($date);
echo timezone_name_get($tz), PHP_EOL;
echo $tz->getName(), PHP_EOL;
echo get_class($tz), PHP_EOL; How It Works
- The date is created with the Asia/Kolkata timezone.
- date_timezone_get() returns a DateTimeZone object for that date.
- timezone_name_get() and the getName() method both return the same name.
- get_class() confirms the result is a DateTimeZone object.

