Rails: convert UTC DateTime to another time zone
if Time.zone
it's your desired time zone then you can use @date.to_time.to_datetime
> @date
=> Tue, 02 Sep 2014 23:59:59 +0000
> @date.class
=> DateTime
> @date.to_time
=> 2014-09-02 12:59:59 -1100
> @date.to_time.to_datetime
=> Tue, 02 Sep 2014 12:59:59 -1100
time.in_time_zone(time_zone)
Example:
zone = ActiveSupport::TimeZone.new("Central Time (US & Canada)")
Time.now.in_time_zone(zone)
or just
Time.now.in_time_zone("Central Time (US & Canada)")
You can find the names of the ActiveSupport time zones by doing:
ActiveSupport::TimeZone.all.map(&:name)
# or for just US
ActiveSupport::TimeZone.us_zones.map(&:name)