[Ruby] Rails3: time zone の設定
自分の作った Rails 3アプリではデータベースの列に日付型を使っているのだけど
デフォルトの日付が日本時間とずれている気がする。
そういえば、time zone の設定があるとかどっかで見た気がしたので
$ cd myrails_app_directory
$ find . -type f | xargs grep -i time | grep -i zone
./config/application.rb: # Set Time.zone default to the specified zone and
make Active Record auto-convert to this zone.
./config/application.rb: # Run "rake -D time" for a list of tasks for finding
time zone names. Default is UTC.
./config/application.rb: # config.time_zone = 'Central Time (US & Canada)'
なるほど。Active Record は、time zone の設定に合わせて自動変換するのね。
説明に従って "rake -D time" を実行
$ rake -D time
rake time:zones:all
Displays all time zones, also available: time:zones:us, time:zones:local -- filter
with OFFSET parameter, e.g., OFFSET=-6
更にメッセージに従って、
$ rake time:zones:local
* UTC +09:00 *
Irkutsk
Osaka
Sapporo
Seoul
Tokyo
config/application.rb を編集
config.time_zone = 'Tokyo'
これで、日本時間に合うようになった。
Seoul ってソウルのことなのか。
| 固定リンク
この記事へのコメントは終了しました。
コメント