2

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

3 Answers 3

4
require 'time'
Time.parse("Mon Mar 15 20:51:18 +0000 2010").to_i
Sign up to request clarification or add additional context in comments.

Comments

3

Just call ".to_i" on your DateTime object

1 Comment

There is no to_i on DateTime, you have to go via Time, i.e. .to_time.to_i
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.