I want to change the posting time from international standard time to Japan time
--Added the description of
config.time_zone ='Tokyo' in
config / application.rb
#↑ Codes before this are omitted module App class Application < Rails::Application config.time_zone = 'Tokyo' end end
--If the server is up, shut it out and start it up again
docker-compose up -d
** This will be displayed in Japan time, but the format needs to be changed separately **
strftime method to apply the method to the part where you want to change the display format.
#Below is a sample <td><%= @tweet.created_at.strftime('%Y year%m month%d day%H o'clock%M minutes') %></td>
** What to do: Define format conversion in Initialize **
--Create a file called
config / initializers
Time :: DATE_FORMATS [: datetime_jp] ='% Y year% m month% d day% H hour% M minute'
Time::DATE_FORMATS[:datetime_jp] = '%Y year%m month%d day%H o'clock%M minutes'
--Write .to_s (: datetime_jp]) in the part you want to use (in the view file) and use it.
#Below is a sample <td><%= @tweet.created_at.to_s(:datetime_jp) %></td>