How can I get the local server's time zone?

前端 未结 6 1523
庸人自扰
庸人自扰 2021-01-02 01:53

How can I get the local server\'s timezone without relying on php.ini or other configuration files?

I am looking for an output similar to the output of

6条回答
  •  鱼传尺愫
    2021-01-02 02:06

    If you're using a Linux/Unix based hosting platform, you could use the output of the date command with the "alphabetic time zone abbreviation" formatter as such:

    $systemTimeZone = system('date +%Z');
    

    However, it should be noted that you shouldn't necessarily rely on the system's timezone and that you should instead use date_default_timezone_set (or the date.timezone php.ini setting) to set the required timezone.

提交回复
热议问题