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

tony · 2011年10月31日 · 最后由 rdongxie 回复于 2014年12月02日 · 11365 次阅读

将字符串转换为时间戳 比如将 "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

需要 登录 后方可回复, 如果你还没有账号请 注册新账号