开发者

Add seconds (in fixnum format) to a datetime, Rails

I need to pass a variable to my view with Time.now + @seconds in time format (i.e. 12pm + 3600 seconds = 1:00pm, whic开发者_运维技巧h goes to the view).

Time.now + @seconds #seconds is a fixnum

doesn't work because "Time can't be coerced into Fixnum". How then can I generate this simple result?


Don't barbeque me if this is wrong now but back when I was doing Rails you would just say Time.now + @seconds.seconds . Also @seconds.seconds.from_now


Today I learned that (1.second + DateTime.now) != (DateTime.now + 1.second)

to answer your question try using Time.now + @seconds.seconds or Time.now + @seconds.to_i.seconds


Another example

DateTime.current + 20.seconds
=> Mon, 11 Jan 2021 18:06:04 +0000
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜