我有一个这样的代码
if user.created_at >= 1563724800
do sth
end
其中user.created_at绝对大于1563724800。但它仍然返回false。我必须使用user.created_at.to_i >= 1563724800
来获得我所期望的东西。所以我想知道它是如何工作的。
发布于 2019-08-05 04:59:51
据我所知,你应该这样做(用DateTime比较一个整数,也把它转换成整数)-
if user.created_at.to_i >= 1563724800
do sth
end
或者应该进行反向比较(将整数转换为DateTime)
if user.created_at >= Time.at(1563724800)
do sth
end
自纪元以来的整数秒数的time.to_i => int时间。
具有给定秒数的Time.at(seconds) => time =>新时间对象
https://stackoverflow.com/questions/57352067
复制相似问题