[Ruby] Change the default timezone of the rails app

less than 1 minute read


The published application Date.today could get the local time in the development environment, but when it was published, it was in UTC time.

What I did

Change the default time zone to Japan time

(app name)/config/application.rb

config.time_zone ='Asia/Tokyo'

As a result, although it is registered as UTC time in the database, it is displayed as the time of Tokyo in the application (I think you can see that it was UTC+9:00).

As a method to get today’s date Change from Date.today to Time.zone.today

By default, it is registered in UTC time in the database, and it is often changed to the local date and time using Time.zone, so remember this method.