How to use the strftime method
suggest changeConverting a time to a string is a pretty common thing to do in Ruby. strftime is the method one would use to convert time to a string.
Here are some examples:
Time.now.strftime("%Y-%m-%d %H:%M:%S") #=> "2016-07-27 08:45:42"
%S is seconds. %M:S is minutes, a colon, and a literal S.
%F is %Y-%m-%d. %X is the locale’s preferred time, which is often %H:%M:%S but not always:
Time.now.strftime("%F %X") #=> "2016-07-27 08:45:42"
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents