最終的には、RailsのActiveRecord保存時間とログの時刻を日本時刻に変えたいのですが、設定方法をご教授いただけますと幸いです。
以下をご参照いただき問題のありそうなところを指摘いただけますと幸いです。
環境
CentOS7.4
Rails 5.2.1
Railsのconfig
config/application.rb
config.time_zone = 'Tokyo' config.active_record.default_timezone = :local
Rails Console実行結果
Createなどによってcreated_atに保存される時刻が、Time.nowの値と同じ時刻になってしまっていますが、これをTime.currentの時刻にしたいです。
irb(main):002:0> Time.now => 2019-04-28 05:44:41 +0000 irb(main):003:0> Time.current => Sun, 28 Apr 2019 14:44:43 JST +09:00
Rails Logの表示
D, [2019-04-28T05:44:30.469466 #30072]....
CentOS実行結果
$ date 2019年 4月 28日 日曜日 05:45:27 Tokyo
$ timedatectl Warning: Ignoring the TZ variable. Reading the system's time zone setting only. Local time: 日 2019-04-28 14:45:53 JST Universal time: 日 2019-04-28 05:45:53 UTC RTC time: 日 2019-04-28 14:45:52 Time zone: Asia/Tokyo (JST, +0900) NTP enabled: yes NTP synchronized: yes RTC in local TZ: yes DST active: n/a Warning: The system is configured to read the RTC time in the local time zone. This mode can not be fully supported. It will create various problems with time zone changes and daylight saving time adjustments. The RTC time is never updated, it relies on external facilities to maintain it. If at all possible, use RTC in UTC by calling 'timedatectl set-local-rtc 0'.
# hwclock 2019年04月28日 14時48分42秒 -0.670552 秒
修正を試みるために実行したコマンド
上記の実行結果は全て以下のコマンド実行後のものです。
hwclock -s --localtime timedatectl set-local-rtc true
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。