PHP 5.4 Can't Determine Time Zones on its own

前端 未结 6 1081
忘了有多久
忘了有多久 2020-12-20 12:59

I\'m just looking for a little clarification on this. PHP 5.4 eliminated the TZ environmental variable and the \"guessing\" that date_default_timezone_get used

6条回答
  •  旧巷少年郎
    2020-12-20 13:23

    On a Windows server, it is possible to get the local system time zone with a little bit of math:

    diff($nowSys);
    
      echo $nowUTC->format('H:i:s') . '
    '; echo $nowSys->format('H:i:s') . '
    '; echo $offset->format('%H'); ?>

    From my locale (UTC-05) at the time of writing the output of this code is:

    22:16:41
    17:16:41
    05
    

    There is one caveat: the timestamps can sometimes be off by 1 second, causing the $offset variable to have 4:59:59. Getting the correct timezone consistently should do a little bit of rounding to be safe.

提交回复
热议问题