gpt4 book ai didi

mysql - Laravel 5 时间戳不更新正确的时间

转载 作者:可可西里 更新时间:2023-11-01 07:20:03 25 4
gpt4 key购买 nike

将记录插入数据库后,created_at 时间戳显示不正确,它从服务器延迟 2 小时....另外如果我输入 mysql SELECT NOW() 它显示正确的时间,知道有什么问题吗?

编辑..

它从 Carbon 类获取日期...知道如何更改它吗?

最佳答案

laravel 的默认 timezoneUTC,它位于 config/app.php 文件中。

如果您想将timezone 更改为您首选的timezone,请从this list 中选择您首选的timezone或来自 this list并将 UTC 替换为您选择的时区。

一些注意事项。根据 comments here ,准确地说,最后 3 条评论:您不应该更改默认值。

Storing dates of different timezones in data source of a same application (by changing the timezone in config for current user & letting Laravel handle it from there on) is just asking for trouble & is a bad design. You will lose data integrity. What will happen when a user changes timezone? You'll update all the dates in the database for that user?

Store dates for all users as UTC (or any other timezone of your choosing, just select one & stick to it). Laravel already uses the excellent Carbon library, use it to convert dates from your timezone (in which they're stored in DB) to users' timezone (which you would store with in every user's settings) when you display the dates.

关于mysql - Laravel 5 时间戳不更新正确的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31728407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com