开发者

Convert a date string to a Unix timestamp

开发者 https://www.devze.com 2022-12-23 04:34 出处:网络
I have this date \"Mon Mar 15 20:51:18 +0000 2010\". How 开发者_StackOverflow中文版do i convert this date into a Unix timestamp?require \'time\'

I have this date "Mon Mar 15 20:51:18 +0000 2010". How 开发者_StackOverflow中文版do i convert this date into a Unix timestamp?


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


Just call ".to_i" on your DateTime object


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号