时间戳与数据库不一样(Laravel)
我有一些数据。在数据库mysql 8
上。 Create_at字段看起来像2022-06-25 07:44:43。
,
但是当我获取数据时,它返回
“ create_at”:“ 2022-06-25T05:44:43.00000000Z”
我将 config/app.php 的时区设置为欧洲/法国,但时间似乎仍然落后2个小时。
在提取期间,哪种机制发生了变化?为什么我不从数据库中获取相同的数据?
下面的代码解决了我的问题,但我只是对这个问题感到好奇。
public function getCreatedAtAttribute($value) {
return Carbon::createFromTimestamp(strtotime($value))
->timezone(env("APP_TIMEZONE"))
->toDateTimeString();
}
I have some data. On the database mysql 8
. Created_at field seems like 2022-06-25 07:44:43.
But when I fetch the data, it returns
"created_at": "2022-06-25T05:44:43.000000Z"
I have set my timezone from config/app.php as Europe/France but the time seems still 2 hours behind.
Which mechanism changes that time during the fetch? Why don't I get the same data from the database?
The code below solves my problem but I am just curious about this problem.
public function getCreatedAtAttribute($value) {
return Carbon::createFromTimestamp(strtotime($value))
->timezone(env("APP_TIMEZONE"))
->toDateTimeString();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误设置了数据库服务器上的时区。
如果您在Linux运行
或时区,则需要
The timezone on your database server is wrongly set.
If you are under linux run
Or the timezone you need