I am learning programming and I choose Ruby as the first language to learn.
I am parsing an XML where dates are in this form: 1240915075 1224855068
How is this format called? How to use that value in a Date or Time object?
Thank you!
This is UNIX time (sometimes called Epoch time). It measures the number of seconds elapsed since January 1, 1970 (The Unix epoch is the time 00:00:00 UTC on 1 January 1970)
Here's an example converter: http://www.esqsoft.com/javascript_examples/date-to-epoch.htm
A stackoverflow question regarding converting integer time using Ruby: Ruby / Rails: convert int to time OR get time from integer?
use the Time.at function to convert e.g.:
t = Time.at(i)
That's Epoch Time (the first one corresponds to Tue Apr 28 2009 11:37:55 GMT+0100).
You can get a datetime out of it, using Time.at
, like this:
Time.at(1240915075)
That is a unix timestamp - the number of seconds since jan 1st 1970.
An example of how to use it in Ruby is here:
t = Time.at(1215163257)
puts t.to_date
>> 2008-07-04
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With