こんばんは。
表題についてお聞きしたいことがあります。
現在pythonでスクレイピングしたデータをMAMPのMySQLに格納するものを作っているのですが、
格納した時刻をcreated_at、更新した時刻をupdated_atカラムに格納しています。
うまく値(時刻)の格納はされているのですが、9時間ほどずれた時刻で格納されており
どうやらUTCの時刻で格納されているような感じがします。
スクレイピングした(値をDBに格納した)日本時間(JTC)で、格納されるにはどのようにすればよろしいでしょうか。
下記に自分で作成したSQLと確認したMySQLの情報などを記載します。
環境
macOS High Sierra 10.13.4
MAMP Pro
MySQL : 5.6.38
sql
1create table test_tables 2( 3 id int(11) unsigned auto_increment 4 primary key, 5 title varchar(255) null, 6 date date null, 7 time time null, 8 url varchar(255) null, 9 url_hash char(64) null, 10 created_at timestamp default CURRENT_TIMESTAMP not null, 11 updated_at timestamp default CURRENT_TIMESTAMP not null 12 on update CURRENT_TIMESTAMP, 13 content text null, 14 constraint test_tables_url_hash_uindex 15 unique (url_hash) 16) 17 engine = InnoDB 18 auto_increment = 3, 19 charset = utf8mb4;
mysql
1 2// これは先ほど(21時30分頃)に取得した内容です 3mysql> select created_at,updated_at from test_tables; 4+---------------------+---------------------+ 5| created_at | updated_at | 6+---------------------+---------------------+ 7| 2018-04-23 12:31:04 | 2018-04-23 12:31:04 | 8| 2018-04-23 12:31:04 | 2018-04-23 12:31:04 | 9| 2018-04-23 12:31:04 | 2018-04-23 12:31:04 | 10| 2018-04-23 12:38:16 | 2018-04-23 12:38:16 | 11| 2018-04-23 12:38:16 | 2018-04-23 12:38:16 | 12| 2018-04-23 12:38:16 | 2018-04-23 12:38:16 | 13| 2018-04-23 12:39:24 | 2018-04-23 12:39:24 | 14| 2018-04-23 12:39:24 | 2018-04-23 12:39:24 | 15+---------------------+---------------------+ 168 rows in set (0.00 sec) 17 18mysql> select version(); 19+-----------+ 20| version() | 21+-----------+ 22| 5.6.38 | 23+-----------+ 24 25mysql> select NOW(); 26+---------------------+ 27| NOW() | 28+---------------------+ 29| 2018-04-23 21:42:41 | 30+---------------------+ 311 row in set (0.00 sec) 32 33mysql> show variables like '%time_zone%'; 34+------------------+--------+ 35| Variable_name | Value | 36+------------------+--------+ 37| system_time_zone | JST | 38| time_zone | SYSTEM | 39+------------------+--------+ 40
console
1$ date 22018年 4月23日 月曜日 22時01分36秒 JST
どうぞ宜しくお願い申し上げます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/04/23 14:40
2018/04/24 00:27
2018/04/24 10:05