get server time in php - timezone issues

前端 未结 4 1441
攒了一身酷
攒了一身酷 2020-12-13 20:41

on shell, my server time is (simple date in bash): Sun Aug 29 10:37:12 EDT 2010

when I run the code php -r \"echo date(\'Y-m-d H:i:s\');\"

4条回答
  •  有刺的猬
    2020-12-13 21:17

    According to the php.ini directives manual page, the timezone isn't set by default if you're using a version prior to 5.3. Then if you take a look at the page for date_default_timezone_get, it uses the following order for getting the timezone:

    * 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)
    

    UTC is the default if all of those fail, so that's probably a good starting point.

提交回复
热议问题