【问题标题】:How to make all database changes follow UTC timezone?如何使所有数据库更改遵循 UTC 时区?
【发布时间】:2019-01-27 05:38:47
【问题描述】:

我正在使用 Laravel 5.5 和 MySQL,所有这些都托管在 AWS 上。

当我运行date 命令时,我在app.php 中将时区设置为UTC,服务器中的时间也是UTC

但是,当我从应用程序的仪表板中删除模型对象时,updated_at 设置为我的计算机时间而不是 UTC。也就是说,deleted_at 设置为 UTC!只是updated_at 我有问题。

这是在 Laravel 中删除对象的代码:

/**
 * Remove the specified resource from storage.
 *
 * @param $eventId
 *
 * @return Response
 *
 * @internal param int $id
 */
public function destroy( $eventId ) {
    $this->eventsService->dashboard->delete( $eventId );
    flash( 'Event has been deleted', 'success' );
    if ( str_contains( $_SERVER['HTTP_REFERER'], 'events/' . $eventId . '/edit' ) ) {
        return redirect( '/events' );
    }

    return redirect( $_SERVER['HTTP_REFERER'] );
}

这是来自app.php

'timezone'        => 'UTC',

这是我在服务器上运行 date 时:

Tue Aug 21 04:48:42 UTC 2018

这是一个计划作业,将事件状态(该应用程序用于旅行体验)从 future 更新为 current ...etc,它使用 Carbon 包:

$schedule->command(EventsUpdateStatus::class)->everyMinute();

当我在 DB 上运行:SELECT @@global.time_zone, @@session.time_zone; 时,它会显示:UTC

还有什么要检查以确保 updated_at 遵循 UTC?

【问题讨论】:

    标签: php amazon-web-services datetime laravel-5 utc


    【解决方案1】:

    您必须更改 MySql 全局参数以设置默认时区

    查看以下链接

    https://dba.stackexchange.com/questions/20217/mysql-set-utc-time-as-default-timestamp

    【讨论】:

      猜你喜欢
      • 2011-07-18
      • 1970-01-01
      • 2017-06-01
      • 1970-01-01
      • 2013-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多