简体   繁体   中英

TimeZone location to offset in PHP

Google Calendar's XML feed includes a value to indicate the timezone of the calendar , but it only includes a long format time zone ID, rather than the time offset.

eg

<gCal:timezone value="Australia/Hobart"/>

or

<gCal:timezone value='Europe/London'/>

Is there an easy way to translate these location values into aa timezone offset (like +11 hours ?) This value would need to reflect the current daylight saving status of the locale.

Alternatively, is there any way to get Google Calendar to include this timezone offset in the XML data?

This will give you the timezone offset in seconds, relative to UTC:

$timezone = 'Europe/London';
$dt = new DateTime('now', new DateTimeZone($timezone));
echo $dt->getOffset();

You can get a list of all supported timezones by calling

DateTimeZone::listIdentifiers() 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM