Ruby / Rails:将整数转换为时间或从整数获取时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2871402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ruby / Rails: convert int to time OR get time from integer?
提问by www
We can do this:
我们可以完成这个:
i = Time.now.to_i
for example current:
例如当前:
i = 1274335854
can I convert i back to time?
我可以将我转换回时间吗?
回答by polygenelubricants
time.to_i => int: Returns the value of timeas an integer number of seconds since epoch.
Time.at(seconds[, microseconds]) => time:Creates a new time object with the given number of seconds (and optional microseconds) from epoch.
time.to_i => int:以自纪元以来的整数秒数形式返回时间值。
Time.at(seconds[, microseconds]) => time:从纪元开始创建一个具有给定秒数(和可选微秒数)的新时间对象。

