How would I get a UNIX timestamp (number of seconds since 1970 GMT) from a Date object in a Rails app?
I know Time#to_i
returns a timestamp, but doing <
I get the following when I try it:
>> Date.today.to_time.to_i
=> 1259244000
>> Time.now.to_i
=> 1259275709
The difference between these two numbers is due to the fact that Date
does not store the hours, minutes or seconds of the current time. Converting a Date
to a Time
will result in that day, midnight.