开发者

Ruby / Rails: convert int to time OR get time from integer?

We can do this:

i = Time.now.to_i 

for example current:

i = 1274335854
开发者_如何学运维

can I convert i back to time?


Use Time.at:

t = Time.at(i)


time.to_i => int: Returns the value of time as 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.

API links

  • ruby-doc.org/core/classes/Time
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜