More than 1 year has passed since last update.

DBのcreatedやmodifiedの時間がデフォルトだとUTCだったので『Asia/Tokyo』に変更しました。

ソース変更

変更箇所は以下の2ファイル
* config/app.phpのDatasources

'Datasources' => [
        'default' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'persistent' => false,
            'host' => 'localhost',
            /**
             * CakePHP will use the default DB port based on the driver selected
             * MySQL on MAMP uses port 8889, MAMP users will want to uncomment
             * the following line and set the port accordingly
             */
            //'port' => 'nonstandard_port_number',
            'username' => 'user',
            'password' => 'password',
            'database' => 'test',
            'encoding' => 'utf8',
            'timezone' => 'Asia/Tokyo',
            'cacheMetadata' => true,

            /**
             * Set identifier quoting to true if you are using reserved words or
             * special characters in your table or column names. Enabling this
             * setting will result in queries built using the Query Builder having
             * identifiers quoted when creating SQL. It should be noted that this
             * decreases performance because each query needs to be traversed and
             * manipulated before being executed.
             */
            'quoteIdentifiers' => false,

            /**
             * During development, if using MySQL < 5.6, uncommenting the
             * following line could boost the speed at which schema metadata is
             * fetched from the database. It can also be set directly with the
             * mysql configuration directive 'innodb_stats_on_metadata = 0'
             * which is the recommended value in production environments
             */
            //'init' => ['SET GLOBAL innodb_stats_on_metadata = 0'],
        ],
  • config/bootstrap.php
date_default_timezone_set('Asia/Tokyo');

MYSQL設定

自分の場合、DBエラーが発生しましたがそれはMYSQLに必要な設定をしていなかったせいでした。

SQLSTATE[HY000]: General error: 1298 Unknown or incorrect time zone: 'Asia/Tokyo'

解決法
・コマンドにて実行
参考:http://mysql.stu.edu.tw/doc/refman/5.1/ja/time-zone-support.html

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql -p