I'm currently creating a matching app with Rails, but I use strftime a lot, so I'll summarize how to write it so that you can see it immediately.
It is a method that can display the date and time data in the view as you like.
This time we will do it with created_at.
This is the default. It seems that +0900 at the back is not used. 2020-05-22 16:11:01 +0900
created_at.strftime("%Y-%-m-%-d %-H:%M")
#Display 2020-5-28 20:25
You can convert the character string like this. The symbols are not arranged properly. Lol
I have attached a part of the form below. If you want to know more, please click here. Source pikawaka
Format | Return value | Description |
---|---|---|
%Y | 2019 | Obtain the year as a 4-digit number * "0001" for the first year of the year |
%m | 01 | Be sure to get the month as a two-digit number (01)-12) |
%-m | 1 | Get the month as a 1- or 2-digit number (1)-12) |
%d | 01 | Be sure to get the date in 2 digits (01), 02 ... ) |
%-d | 1 | Get the date in 1 or 2 digits (1), 2 ... 10, 11 ...) |
%H | 12 | Always get the 24-hour time in 2 digits (00)-23) |
%-H | 12 | Get the 24-hour time in 1 or 2 digits (0)-23) |
%I | 12 | Get the 12-hour time in 1 or 2 digits (1)-12) |
%M | 00 | Get minutes (00)-59) |
%S | 00 | Get seconds (00)-60) * 60 is a leap second |
Thank you very much!
Recommended Posts