“date(): It is not safe to rely on the system's timezone settings…”

前端 未结 24 1949
予麋鹿
予麋鹿 2020-11-22 11:06

I got this error when I requested to update the PHP version from 5.2.17 to PHP 5.3.21 on the server.

相关标签:
24条回答
  • 2020-11-22 11:45
    <? print(gmdate("Y")); ?> 
    

    instead of

    <? print(date("Y")); ?>
    

    worked for me (shows current year and no more shows the error message). (Thanks to Chris above)

    0 讨论(0)
  • 2020-11-22 11:45

    A simple method for two time zone.

    <?php 
    $date = new DateTime("2012-07-05 16:43:21", new DateTimeZone('Europe/Paris')); 
    
    date_default_timezone_set('America/New_York'); 
    
    echo date("Y-m-d h:iA", $date->format('U')); 
    
    // 2012-07-05 10:43AM 
    ?>
    
    0 讨论(0)
  • 2020-11-22 11:45
    <? date_default_timezone_set('Europe/Istanbul'); ?>
    

    For php (or your location).

    0 讨论(0)
  • 2020-11-22 11:47

    This issue has been bugging me for SOME time as im trying to inject a "createbucket.php" script into composer and i keep being told my time-zone is incorrect.

    In the end the only thing that fixed the issue was to: $ sudo nano /etc/php.ini

    Search for timezone

    [Date]
    ; Defines the default timezone used by the date functions
    ; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
    date.timezone = UTC
    

    Ensure you remove the ;

    Then finally

    $ sudo service httpd restart
    

    And you'll be good to go :)

    0 讨论(0)
  • 2020-11-22 11:47

    I had to put it in double quotes.

    date_default_timezone_set("America/Los_Angeles"); // default time zone
    
    0 讨论(0)
  • 2020-11-22 11:47

    If you don't have access to the file php.ini, create or edit a .htaccess file in the root of your domain or sub and add this (generated by cpanel):

    <IfModule mime_module>
    AddType application/x-httpd-ea-php56 .php .php5 .phtml
    </IfModule>
    
    <IfModule php5_module>
    php_value date.timezone "America/New_York"
    </IfModule>
    
    <IfModule lsapi_module>
    php_value date.timezone "America/New_York"
    </IfModule>
    
    0 讨论(0)
提交回复
热议问题