Unify the Rails app time zone to Japan time

There are four time zones to consider:

--Ruby process --Affects Time.now etc.

Ruby process

Development environment (Docker)

Added ʻENV TZ Asia / Tokyo to Dockerfile` to support

Production environment

Corresponding by setting TZ = Asia / Tokyo in the environment variable

config.time_zone

Common

config/application.rb


config.time_zone = 'Tokyo'

config.active_record.default_timezone

Common

config/application.rb


config.active_record.default_timezone = :local

DB Connect to each DB of development environment and production environment and execute the following query

ALTER DATABASE db_name SET timezone TO 'Asia/Tokyo';

Since it is the writing method for Postgres, the writing method may differ depending on the type of DB. It will be reflected when you reconnect to the DB. Executing rails: db: migrate will restore the timezone, but it's okay because you rarely write SQL statements in Rails in the first place. There seems to be a way to set environment variables in docker-compose.yml, but it didn't work.

reference

-Rails time zone summary-Qiita

Recommended Posts

Unify the Rails app time zone to Japan time
How to set the display time to Japan time in Rails
I tried to introduce Bootstrap 4 to the Rails 6 app [for beginners]
[PostgreSQL] If you want to delete the Rails app, delete the database first!
Use Timecop in Rails web app to travel time on your browser
How to change app name in rails
I tried to introduce CircleCI 2.0 to Rails app
Introduction to java for the first time # 2
Change the default timezone for the rails app
[Rails] How to use the map method
Introduced Vue.js to an existing Rails app
Upload Rails app image file to S3
The story of releasing the Android app to the Play Store for the first time.
[Java] How to set the Date time to 00:00:00
Try deploying Rails app to EC2-Part 2 (Deploy)-
How to compare only the time with Rails (from what time to what time, something like)
The process of introducing Vuetify to Rails
[Rails] How to apply the CSS used in the main app with Administrate
Introduced Vuetify to an existing Rails app
[Rails] How to solve the time lag of created_at after save method
Change the save destination of the image to S3 in the Rails app. Part 2
[Rails] How to decide the destination by "rails routes"
Short URL to the App Store developer page
[Rails] Button to return to the top of the page
[Rails] I tried to raise the Rails version from 5.0 to 5.2
I tried to organize the session in Rails
Publish the app made with ruby on rails
Set the time of LocalDateTime to a specific time
How to add sound in the app (swift)
Ssh login to the app server on heroku
[Swift] How to link the app with Firebase
The code I used to connect Rails 3 to PostgreSQL 10
Create an app by specifying the Rails version
Try to summarize the common layout with rails
How to check Rails commands in the terminal
[Rails] How to convert UC time display to Japanese time display
How to run the SpringBoot app as a service
What to do if the Rails server can't start
How to push an app developed with Rails to Github
How to remove the underline displayed by Rails link_to
[Heroku] Associate AWS S3 with the deployed Rails app
It's about time to face the parenthesized monster (JavaScript)
[Ruby on Rails] How to change the column name
[Updated from time to time] Ruby on Rails Convenient methods
I want to know the answer of the rock-paper-scissors app
[Rails] I don't know how to use the model ...
I want to dark mode with the SWT app
[Rails] How to change the column name of the table
[Rails] How to get the contents of strong parameters
Addicted to the webpacker that comes standard with Rails 6
Kotlin may take the world from App to Web
Make the strongest Laravel development environment (Docker) Japan time
How to get started with creating a Rails app
Command to try using Docker for the time being
[Rails] How to display an image in the view
My 1880's ~ Fixed time zone from LMT to JST ~
How to study kotlin for the first time ~ Part 2 ~
[Rails] Validate the start time (datetime type) and end time
How to study kotlin for the first time ~ Part 1 ~