Guessing User's TimeZone in PHP

后端 未结 2 794
悲&欢浪女
悲&欢浪女 2020-12-11 12:32

As of PHP5.3 (I think) it became a requirement for the date.timezone to be set in the php.ini file, or to be set at runtime via the date_default_ti

2条回答
  •  情歌与酒
    2020-12-11 13:13

    I'd probably use the date_default_timezone_get() function:

    string date_default_timezone_get  ( void  )
    

    In order of preference, this function returns the default timezone by:

    • Reading the timezone set using the date_default_timezone_set() function (if any)
    • Reading the TZ environment variable (if non empty) (Prior to PHP 5.3.0)
    • Reading the value of the date.timezone ini option (if set)
    • Querying the host operating system (if supported and allowed by the OS)

    http://www.php.net/manual/en/function.date-default-timezone-get.php

提交回复
热议问题