www www - 10 days ago 7
Ruby Question

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?

Answer

Use Time.at:

t = Time.at(i)