Skip to content

Instantly share code, notes, and snippets.

@tranchausky
Created August 19, 2024 10:29
Show Gist options
  • Save tranchausky/8e5f9bfc94d06ca547a4e2d5fd91e766 to your computer and use it in GitHub Desktop.
Save tranchausky/8e5f9bfc94d06ca547a4e2d5fd91e766 to your computer and use it in GitHub Desktop.
<?php
// Define the timezone identifier for California
$timezoneIdentifier = 'America/Los_Angeles';
// Create a DateTimeZone object with the specified timezone
$timezone = new DateTimeZone($timezoneIdentifier);
// Get the timezone offset in seconds
$offset = $timezone->getOffset(new DateTime('now', $timezone));
// Convert offset to hours
$offsetHours = $offset / 3600;
// Output timezone and offset
echo 'Timezone: ' . $timezoneIdentifier . PHP_EOL;
echo 'Offset: ' . $offsetHours . ' hours from UTC' . PHP_EOL;
//Timezone: America/Los_Angeles
//Offset: -7 hours from UTC
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment