Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert epoch time in Ruby

Tags:

linux

ruby

Is there a simple way to convert Epoch time to standard format with Ruby? If so can I customize the way it is displayed?

like image 348
BlackHatSamurai Avatar asked Feb 08 '13 00:02

BlackHatSamurai


1 Answers

Use the Time.at method:

Time.at(1234567890) #=> 2009-02-13 16:31:30 -0700

To display the time, you can use the method strftime on the resulting object.

For instance:

Time.at(1234567890).strftime("%m/%d/%Y") #=> "02/13/2009"
like image 176
Daniel Evans Avatar answered Sep 21 '22 04:09

Daniel Evans