Summary of Japan time setting and display method

Introduction

A memorandum for myself It's easy to forget, so I'll summarize it

procedure

Japan time setting

Application file editing

config/application.rb


#Omission

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

    #Japanese language setting
    config.i18n.default_locale = :ja
    #Japan time setting
    config.time_zone = 'Tokyo'

    #Omission

Set the time format

config/locales/ja.yml =>Create

config/locales/ja.yml


ja:
  time:
    formats:
      default: "%Y/%m/%d %H:%M:%S"
      #Since it is the default to the last, set with a pattern that seems to be used often

Time display

l method

sample.rb


l sample.created_at =>Display with default settings

Specify the display method

sample.rb


sample.created_at.strftime('20%y year%m month') => "20xx yy month"

in conclusion

Am I the only one who thinks the l method sounds cool?

✔︎

Recommended Posts

Summary of Japan time setting and display method
Japanese localization of Docker container of CentOS7 / CentOS8 and Japan time setting
Setting method to link Java of Eclipse and Github / September 2017
A brief summary of DI and DI containers
Explanation of Ruby Time and Date objects
Summary of hashes and symbols in Ruby
Summary of CR, LF, CRL of open method
Summary of Java Math.random and import (Calendar)
[Java] Personal summary of classes and methods (basic)
Date and time acquisition method using DateAndTime API
About call timing and arguments of addToBackStack method
[Must-see for beginners] I changed the display of the posting time to Japanese time [l method]
Environment construction method and troubleshooter at the time of joint development (rails, docker and github)
Date and time
variable and method
Summary of frequently used commands in Rails and Docker
How to set the display time to Japan time in Rails
Summary of ToString behavior with Java and Groovy annotations
[Grails] About the setting area and the setting items of application.yml
Usability of date and time classes in each language
[Eclipse] Summary of environment settings * Updated from time to time
Summary of file reading method for each Java file format
Handling of date and time in Ruby. Use Date and Time properly.
Implementation method of linking multiple images to one post and posting at the same time