PHP date function giving wrong time [solved]


  • | 1167 points

    I can't get the PHP date function to give me the proper time. It is always a 4 hours and ahead.

    I have set the date.timezone = "America/Toronto" and phpinfo() shows that it is set to that. The default timezone is set to UTC and I don't know how to change that as there isn't a variable for it in php.ini file.

    This isn't just happening with Laragon it is also happening on my server. Laragon is running PHP 7.1 and my server is 7.2. I am using php-fpm on my server. I am not sure what Laragon uses.

    Using nginx on my server and Laragon shows both Apache and Ngnix when starting.


  • administrators
    | 97647 points

    @drdan : Can you show a sample code and your expected result?


  • | 2625 points

    Hola @drdan,

    Open config/app.php, then find 'timezone' => 'UTC' and change it to 'timezone' => 'America/Toronto'.

    Please tell us the result.


  • | 1167 points

    Thanks guys. You both hit on my problems.

    Setting the 'timezone' => 'America/Toronto' in the config/app.php file was the solution.

    I didn't mention it but the time was also off by a fraction of an hour rather than exactly 4 hours. This was caused by using m for minutes in the date function rather than i. Thus I was displaying the month not the minutes.

    It is all good now. Thanks again.


Log in to reply
 

Looks like your connection to Laragon was lost, please wait while we try to reconnect.