如何使用 strftime 方法

在 Ruby 中,将时间转换为字符串是很常见的事情。strftime 是用于将时间转换为字符串的方法。

这里有些例子:

Time.now.strftime("%Y-%m-d %H:%M:S") #=> "2016-07-27 08:45:42"

这可以进一步简化

Time.now.strftime("%F %X")  #=> "2016-07-27 08:45:42"