Follow Along as I Stumble on the Path to Learning RoR

Changing the Date from UTC to Another Time Zone

I had some calculations that I wanted to do according to my app’s time zone and not UTC.  Date.today was changing earlier than I wanted it to since the default is to use UTC.  However, I found a simple way to fix this:

in application.rb:

config.time_zone = ‘Eastern Time (US & Canada)’

then you can use this to get the date in the time zone you set:

Time.current.to_date

If do not want to set the time_zone in the configuration, you can just do this:

Time.now.in_time_zone( ‘Eastern Time (US & Canada)’).to_date

Advertisements

Comments are closed.