如何在MySQL中更新日期和时间时修复laravel的错误日期和时间

时间:2019-06-10 05:41:15

标签: php mysql laravel

我目前对在数据库中插入不正确的日期和时间有疑问,我目前使用laravel,在我的app.php中,'timezone'=>'Canada / Central',今天我插入了我的时间和日期为11:23 PM / 09/06/2019的订单,那么在我将订单插入数据库中之后,根据我的时间,order_date不正确。

我的时间和日期:

enter image description here

订单日期和时间插入数据库:

order_date

我将与大家分享我的脚本和代码:

$now = new DateTime();

DB::insert('INSERT INTO order_properties (customer_id,order_ship_address,delivery_status,order_ship_province,order_date,transaction_number) 
        VALUES (?,?,?,?,?,?) ',[

        $hidden_customer_id,
        $hidden_customer_address,
        'Processing',
        Auth::user()->manager_location_assign,
        $now,
        $sessionTransactionNumber


    ]);

1 个答案:

答案 0 :(得分:1)

确保在设置时间中使用了时区。否则,最好使用Eloquent进行数据插入。

PHP var images = {"Counter A":["CounterA1.jpg","CounterA2.jpg"]} // Images to be load on UI for (var key in images) { var imageList = images[key]; console.log(imageList.length) for (i = 0; i < imageList.length; i++) { console.log(imageList[i]) var img = $('<img />').attr({ 'src': 'Image/'+key+'/'+imageList[i] , // this one is displaying Image one below other 'alt': 'Some Image', 'width': 90+"%", 'height':680 }).appendTo('#displayImage'); } } 类不会自动读取laravel设置。

我也建议将时区保存在.env文件中,以便可以在整个应用程序中进行访问。这是您可以为此做的。

  1. 在.env中添加新密钥DateTime

    APP_TIMEZONE

  2. 更新APP_TIMEZONE="America/Chicago" //change as per your timezone.以使用.env设置。

    config/app.php

  3. 您必须使用"timezone" = env("APP_TIMEZONE", "UTC");库并更改代码以获取时区,例如

    Carbon

还要确保您的时区$now = Carbon::now(env("APP_TIMEZONE"));必须在php支持的列表中可用。

这是PHP https://www.w3schools.com/php/php_ref_timezones.asp支持的时区

相关问题