views:

178

answers:

3

I have this date "Mon Mar 15 20:51:18 +0000 2010". How do i convert this date into a Unix timestamp?

+2  A: 
require 'time'
Time.parse("Mon Mar 15 20:51:18 +0000 2010").to_i
+4  A: 

Just call ".to_i" on your DateTime object

Zepplock
A: 

You could definitely use

require 'time'
Time.parse("Mon Mar 15 20:51:18 +0000 2010").to_i

Like user30997 and Zepplock said, however if you have non-standard time string, you might want to use the chronic library.

require 'chronic'
Chronic.parse('tomorrow').to_i

It makes input fields on websites really nice for the end user.

thekingoftruth