Get timezone offset for a given location

前端 未结 3 2107
南旧
南旧 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:44

    To display a local date/time you can use the following, where 'Europe/Berlin' would be replaced with the user's timezone.

    $date = new DateTime($value);
    $date->setTimezone(new DateTimeZone('Europe/Berlin'));
    echo $date->format('Y-m-d H:i:s');
    

提交回复
热议问题