Ruby Ruby 中有 strtotime 这种时间转换函数么?

tony · October 31, 2011 · Last by rdongxie replied at December 02, 2014 · 11362 hits

将字符串转换为时间戳 比如将 "2011-10-31" 或 "2011-10-30 15:00:22" 转换为时间戳

找到问题了

DateTime.parse(last_time).to_time.to_i if !last_time.nil?

之前因为 last_time 为空总报错

>> Date.parse "2011-10-31"
=> Mon, 31 Oct 2011
>> Time.parse "2011-10-30 15:00:22"
=> 2011-10-30 15:00:22 +0800

转换为时间戳? 秒计数: Time.now.to_i

毫秒计数 Time.now.to_f

You need to Sign in before reply, if you don't have an account, please Sign up first.