简体   繁体   English

Laravel 中返​​回的时间不正确

[英]incorrect time returned in laravel

This is a strange problem这是一个奇怪的问题

I am using date functions to get time too but it returns wrong time我也在使用日期函数来获取时间,但它返回错误的时间

return date('Y-m-d H:i:s');

This returns 2017-4-21 09:41:44 but the current time is 14:41:44 There is something wrong with hours .这将返回2017-4-21 09:41:44 ,但目前的时间是14:41:44有什么毛病hours I tried NOW() in MySQL and it gave me correct timing but laravel PHP did not.我在 MySQL 中尝试了NOW() ,它给了我正确的时间,但 Laravel PHP 没有。 Can someone help?有人可以帮忙吗?

In laravel project go to project/config there is a file app.php , in this file search for:在 laravel 项目中,去project/config有一个文件app.php ,在这个文件中搜索:

'timezone' => '';

pass your timezone value in it like:在其中传递您的时区值,例如:

'timezone' => 'Asia/Kolkata', // I am using this for India

And try again, now you will get the correct time as per your timezone.再试一次,现在您将根据您的时区获得正确的时间。

Note: After passing the timezone value run the command php artisan config:cache to clear the cache so that you get the updated data.注意:传递时区值后,运行命令php artisan config:cache清除缓存,以便获得更新的数据。

Timezone list reference时区列表参考

You can set your timezone in the Laravel config files .你可以在Laravel 配置文件中设置你的时区。 The default value is UTC .默认值为UTC

Make sure this is set to your correct timezone.确保将其设置为正确的时区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM