Function date_default_timezone_set() is not available

前端 未结 3 587
情深已故
情深已故 2020-12-10 14:14

As the title says, can anybody explain why the code

ini_set( \'date.timezone\', \'Europe/Athens\' );

works but

date_default         


        
相关标签:
3条回答
  • 2020-12-10 14:47

    You must be using an old version of PHP.

    date_default_timezone_set is for PHP 5.1.2 and above.
    

    Try php -v and check your PHP version.

    0 讨论(0)
  • 2020-12-10 14:50

    You can use:

    putenv("TZ=Europe/Berlin"); // PHP 4
    
    0 讨论(0)
  • 2020-12-10 14:55

    localhost

    server

    It's quite late, I got the same issue and I see there is the difference, I post the screenshot from my localhost and my personal server phpinfo for the timezone.

    On my localhost, date_default_timezone_set('[timezone]') works correctly, however, on the server, it always return the UTC. Based on the php doc, it looks like the timezone is not set in the php ini of my server, so i likely ignored the the timezone set since no value is defined previously.

    Using the init_set, it makes the timezone to be available. I think the timezone is not predefined on the php ini is the cause.

    0 讨论(0)
提交回复
热议问题