Ruby:将unix时间戳转换为日期

时间:2012-04-26 10:51:37

标签: ruby datetime unix-timestamp

irb> dt = Time.now.utc
=> 2012-04-26 10:47:01 UTC

irb> dti = dt.to_i
=> 1335437221

现在,如何将dti转换回日期/时间?

1 个答案:

答案 0 :(得分:104)

使用Time.at

Time.at(1335437221)
# => 2012-04-26 12:47:01 +0200