PHP 5.4 Can't Determine Time Zones on its own

前端 未结 6 1080
忘了有多久
忘了有多久 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:07

    There is no reliable way to guess timezone on every system. Different systems use different conventions and sometimes even different timezone definitions (such as Unix and Windows), sometimes have conflicting timezone specifiers (the same 3-letter zone abbreviation can mean different things in different places). So if you want to have code that is portable between systems, the only way to reliably do it is to ask the user. See for example this thread: http://marc.info/?t=132356551500002&r=1&w=2 on some of the issues with it (look for emails from Derick Rethans - he is the PHP datetime extension maintainer).

    If you have a way to find out timezone that you trust - such as TZ variable - then you could always do date_default_timezone_set($_SERVER['TZ']);. However in general this is not a reliable method, so it must be your decision to trust it, PHP can not make it for you.

提交回复
热议问题