[Rails] How to convert UC time display to Japanese time display

Procedure for changing the time notation

--Install gem'rails-i18n' --Addition of description to config / application.rb --Create and describe files under config / locales

Install gem'rails-i18n'

Add the following Gem to Gemfile. (It will be used in both production and development environments, so let's write it at the bottom.)

Gemfile


gem 'rails-i18n'

Terminal

bundle install

Add description to config / application.rb

Open config / application.rb and add the two lines that say Add.

module application name
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 6.0 
    config.i18n.default_locale = :ja  #add to
    config.time_zone = 'Tokyo'        #add to
   #Omission

Create and describe files under config / locales

Next, let's create a file called ja.yml under config / locales. Write as follows there.

ja:
  time:
    formats:
      default: "%Y/%m/%d %H:%M:%S"

This should have changed to the Japanese time notation.

I think it is displayed like this. スクリーンショット 2020-11-02 11.27.49.png

Y is Year, m is month, d is day, and so on. If you want to change the notation, you can rewrite the default of ja.yml, so please rewrite it to the form you want to display.

Recommended Posts

[Rails] How to convert UC time display to Japanese time display
[rails] How to display db information
[Rails] How to write in Japanese
[Rails] How to convert from erb to haml
[Rails] How to display error messages individually
[Rails] How to use video_tag to display videos
[Rails] How to translate devise into Japanese
How to display error messages in Japanese
[Ruby on Rails] How to display error messages
How to write Rails
How to translate Rails into Japanese in general
How to uninstall Rails
[Rails] How to use Gem'rails-i18n' for Japanese support
[Ruby on Rails] How to write enum in Japanese
[Rails, JS] How to implement asynchronous display of comments
Change date and time to Japanese notation in Rails
[Rails] validates How to translate error sentences into Japanese
[Rails] How to display an image in the view
[rails] How to post images
[Rails] How to use enum
[Rails] How to install devise
[Rails] How to use enum
How to read rails routes
How to terminate rails server
How to write Rails validation
How to write Rails seed
[Rails] How to use validation
[Rails] How to disable turbolinks
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
How to convert Java radix
[Rails] How to implement scraping
[Rails] How to make seed
How to write Rails routing
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
[Rails] How to use Scope
[Rails] How to display the weather forecast of the registered address in Japanese using OpenWeatherMap
From Ruby on Rails error message display to Japanese localization
How to display a graph in Ruby on Rails (LazyHighChart)
[Rails] How to display the list of posts by category
[Rails] How to display information stored in the database in view
[Rails] How to use gem "devise"
How to deploy jQuery on Rails
[Rails] How to install Font Awesome
[Rails] How to use devise (Note)
[Rails] How to use flash messages
[Rails] How to prevent screen transition
How to deploy Bootstrap on Rails
How to convert erb file to haml
[Rails] How to speed up docker-compose
[Rails] How to add new pages
How to convert LocalDate and Timestamp
Rails on Tiles (how to write)
[Rails] How to write exception handling?
[Rails] How to install ImageMagick (RMajick)
[Rails] How to use Active Storage
How to introduce jQuery in Rails 6
[Rails] How to implement star rating
How to return Rails API mode to Rails
How to get along with Rails