[RUBY] Check when created_at, datetime, etc. are not saved in Japan time in Docker and Rails

Conclusion

If the time such as created_at and datetime is not saved in Japan time with Docker and Rails, check the timezone in the ruby ​​container.

If you write it in config like this, a lot will come out. This seems to work if the environment is homebrew.

With docker, it is necessary to set the timezone in the container to Asia/Tokyo.

config/application.rb


module App
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.2

    config.time_zone = 'Asia/Tokyo'
    config.active_record.default_timezone = :local

So add this.

ruby Dockerfile


ENV TZ Asia/Tokyo <=Add here(docker-comopse.yml may be better)

If this doesn't work, you may need to check the timezone of the DB container and set it to'Asia/Tokyo'.

Reference page Change the Docker container timezone setting -Box programming diary.

Check TZ when Time \ .now is not Japan time in Rails \ | TOMILOG

Differences between Time, Date, DateTime, TimeWithZone between Ruby and Rails -Qiita

Organize Rails and surrounding TimeZone settings \ (active \ _record \ .default \ _timezone trap ) -Qiita

How to change TimeZone from UTC to JST with Docker \ + Rails6! The setting method is very easy! – Himakuro Blog

MySQL :: MySQL 5 \ .6 Reference Manual :: 10 \ .6 Time Zone Support on MySQL Server

Recommended Posts

Check when created_at, datetime, etc. are not saved in Japan time in Docker and Rails
[Rails] Precautions when comparing date and time with DateTime
Check points when Windows and Ubuntu shared folder settings are not successful in VirtualBox
[Rails] [Memo] When to add = to <%%> and when not
(Basic authentication) environment variables in rails and Docker
Behavior noticed when adding RadioButton and initial check at the same time in code
Summary of frequently used commands in Rails and Docker
How to set the display time to Japan time in Rails
Change date and time to Japanese notation in Rails
Localhost3000 does not start up in Docker / Rails development.
[Rails] Validate the start time (datetime type) and end time
One of the causes and solutions when whales do not appear in Docker Quickstart Terminal
How to solve the problem when the value is not sent when the form is disabled in rails and sent
What to do when Rails on Docker does not reflect controller changes in the browser