[英]how to change database timezone in lumen?
when insert with eloquent or query builder in lumen project, created_at is wrong and saved UTC.当在 lumen 项目中使用 eloquent 或查询构建器插入时,created_at 是错误的并保存了 UTC。 I set in app.php
我在 app.php 中设置
date_default_timezone_set('Asia/Tehran');
and in env在环境中
DB_TIMEZONE='+04:30'
and in env在环境中
APP_TIMEZONE=Asia/Tehran
but again created at is wrong.i think is bug of lumen.但再次创建是错误的。我认为是流明的错误。
Add this variable to your env
file.将此变量添加到您的
env
文件中。
APP_TIMEZONE=Asia/Tehran
After you have added the variable, run the command below.添加变量后,运行以下命令。
php artisan optimize
If your MySQL server uses the same time zone with PHP, add this code in app.php :如果您的 MySQL 服务器使用与 PHP 相同的时区,请在app.php中添加此代码:
date_default_timezone_set('Asia/Tehran');
$_ENV['DB_TIMEZONE'] = date('P');
In this example date function returns +04:30 or +03:30 based on daylight saving time changes.在此示例中,日期 function根据夏令时更改返回+04:30或+03:30 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.