PHP date function giving wrong time [solved]

  • | 2407 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
    | 131393 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.

  • | 2407 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.

  • | 1055 points

    @leokhoa hi Leo, how to change timezone in Laragon?
    my php time() function return wrong time.
    at php info, it show UTC timezone.
    how can I change it to Indonesia (Jakarta) / UTC+7 timezone?

    i can't find config/app.php mentioned in this thread.


  • administrators
    | 131393 points

    @rustadelo : You can change it in your php.ini (Menu > PHP > php.ini)

  • | 58 points

    Is there a way to Laragon use the date and time from PC?

Log in to reply

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