Setting timezone to UTC (0) in PHP

Setting timezone to UTC (0) in PHP

Asked on January 2, 2019 in PHP.
Add Comment


  • 7 Answer(s)

    Always try to use function which formats the time based on that timestamp named date() If we want to change the time. Because the time() function is a UNIX timestamp and depends on GreenwicMeanTime or UTC .So it cannot be changed.

    If we count the number of milliseconds, since the Unix Epoch which means jan 1 1970 it is called a timestamp.

    echo date('Y-m-d H:i:s T', time()) . "<br>\n";
    date_default_timezone_set('UTC');
    echo date('Y-m-d H:i:s T', time()) . "<br>\n";
    
    Answered on January 2, 2019.
    Add Comment

    Use the code given below,

    <?php
    if (date_default_timezone_set('UTC')){
        echo "UTC is a valid time zone";
    }else{
        echo "The system doesn't know WTFUTC. Maybe try updating tzinfo with your package manager?";
    }
    
    Answered on January 2, 2019.
    Add Comment
    Required. Specifies the timezone to use, like “UTC” or “Europe/Paris”. List of validtimezones: http://www.php.net/manual/en/timezones.php
    Answered on February 17, 2019.
    Add Comment
    echo time() . "<br>\n";
    date_default_timezone_set('UTC');
    echo time() . "<br>\n";
    Answered on May 20, 2019.
    Add Comment
    echo time() . "<br>\n";
    date_default_timezone_set('UTC');
    echo time() . "<br>\n";
    Answered on May 20, 2019.
    Add Comment
    echo time() . "<br>\n";
    date_default_timezone_set('UTC');
    echo time() . "<br>\n";
    Answered on May 20, 2019.
    Add Comment
    echo time() . "<br>\n";
    date_default_timezone_set('UTC');
    echo time() . "<br>\n";
    Answered on May 20, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.