Chen Log

陳洛格

Ruby on Rails 時區 TimeZone 設定

leave a comment »

Ruby on Rails 時區 TimeZone 設定

首先,資料庫裡面的時間一定都是儲存 UTC 時間。
而 Rails 提供的機制是讓你從資料庫拿資料時,
自動幫你轉換時區。例如,要設定台北 +8 時區:

首先設定 config/application.rb

Screen Shot 2012 08 30 at 18 56 34

Screen Shot 2012 08 30 at 18 56 20

中預設時區為

config.time_zone = “Taipei”,

 

如此 ActiveRecord 便會幫你自動轉換時區,
也就是拿出來時 +8,存回去時 -8 。

ps. 改完記得重開Server不然不會有效果

Advertisements

Written by chenagw

2012/08/30 at 18:58

Posted in Uncategorized

Tagged with , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: