How to convert a unix timestamp (seconds since epoch) to Ruby DateTime?

后端 未结 6 633
孤城傲影
孤城傲影 2020-11-30 16:21

How do you convert a Unix timestamp (seconds since epoch) to Ruby DateTime?

6条回答
  •  甜味超标
    2020-11-30 17:11

    This tells you the date of the number of seconds in future from the moment you execute the code.

    time = Time.new + 1000000000 #date in 1 billion seconds
    

    puts(time)

    according to the current time I am answering the question it prints 047-05-14 05:16:16 +0000 (1 billion seconds in future)

    or if you want to count billion seconds from a particular time, it's in format Time.mktime(year, month,date,hours,minutes)

    time = Time.mktime(1987,8,18,6,45) + 1000000000
    

    puts("I would be 1 Billion seconds old on: "+time)

提交回复
热议问题