我在 Ubuntu 服务器上有我的 Laravel Lumen 应用程序,我更改了服务器时区,我的应用程序使用正确的时区成功保存了 created_at、update_at,现在当我获取一些表数据时,我注意到结果时间与在数据库中。
例如:
created_at 在数据库中 =
2020-08-03 13:52:35
created_at =
2020-08-03 10:52:35
按要求更新,以下是我的查询
public function Outbox($id){
$orders = DB::table('order_details as o')
->join('user_profile as a','o.reciever_id','=','a.id')
->join('regions as r','a.province','=','r.province')
->where('o.sender_id' ,'=', $id)
->select('a.bid','r.ar_name as province','o.order_bar','o.price','o.delivery_cost','o.description','o.type','o.dropoff_time as time','o.status','o.visual_status','o.created_at')
->orderBy('o.created_at','desc')
->get();
if(count($orders) > 0){
return response()->json(['status_code'=>1000,'data'=>$orders , 'message'=>null],200);
}else{
return response()->json(['status_code'=>2000,'data'=>null , 'message'=>null],200);
}
}
这里有什么问题??
任何帮助将不胜感激
在您的
bootstrap/app.php
中检查您的时区
date_default_timezone_set(env('APP_TIMEZONE', 'UTC'));
并且不要忘记在您的
APP_TIMEZONE
文件中添加.env
已更新
如果你没有在
bootstrap/app.php
中找到那一行,在引导环境变量之后添加它,比如
<?php
require_once __DIR__.'/../vendor/autoload.php';
(new Laravel\Lumen\Bootstrap\LoadEnvironmentVariables(
dirname(__DIR__)
))->bootstrap();
date_default_timezone_set(env('APP_TIMEZONE', 'UTC'));
并在
.env
中添加
APP_TIMEZONE=UTC
我花了一些时间才发现,在 Lumen 中你必须添加到你的
.env
文件中,例如:
DB_TIMEZONE="Europe/Warsaw"
这应该可以解决问题。
https://github.com/laravel/lumen-framework/blob/8.x/config/database.php
我试过在 app.php 和 .env 文件中设置时区。但没有任何效果。对我有用的是,如果您有权访问数据库,则可以将时间戳数据类型更改为日期时间。