Get timezone offset for a given location

前端 未结 3 2105
南旧
南旧 2021-02-09 08:13

Is it possible in PHP to get the timezone offset for a given location? E.g. when given the location \"Sydney/Australia\" to get the timezone offset as \"+1100\". Bonus would be

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-09 08:52

    You can use the DateTimeZone class.

    getOffset(new DateTime("now")); // Offset in seconds
    echo ($offset < 0 ? '-' : '+').round($offset/3600).'00'; // prints "+1100"
    ?>
    

提交回复
热议问题