rails日期的常用方法


t1 = Time.now
t2 = 1364046539

t1.to_formatted_s(:short)  #long, number
"04 Dec 00:00"
"May 23, 2022 09:18"
"20220523091749"

t1.strftime("%B %e, %Y at %I:%M %p")
=> "March 23, 2013 at 09:48 PM"

t1.strftime("%m/%d/%y %I:%M %p")
=> "03/23/13 09:48 PM"

Time.at(t2)
=> 2013-03-23 21:48:59 +0800


参考: https://stevenyue.com/blogs/date-time-datetime-in-ruby-and-rails/
阅读量: 673
发布于:
修改于: