$date = new DateTime('now', new DateTimeZone('America/New_York')); $offset = $date->getOffset(); echo "The timezone offset for New York is " . $offset . " seconds.";
$date1 = new DateTime('now', new DateTimeZone('America/Los_Angeles')); $date2 = new DateTime('2021-01-01 00:00:00', new DateTimeZone('America/New_York')); $offset1 = $date1->getOffset(); $offset2 = $date2->getOffset(); echo "The timezone offset for Los Angeles is " . $offset1 . " seconds."; echo "The timezone offset for New York on January 1st, 2021 was " . $offset2 . " seconds.";This code creates two `DateTime` objects, one for the current date and time with the timezone set to "America/Los_Angeles" and one for January 1st, 2021 at midnight with the timezone set to "America/New_York". It then gets the offsets for both timezones and prints them to the console. This `getOffset()` method is part of the `DateTime` class in the core PHP library.