Last active
August 29, 2015 13:56
-
-
Save johno/9027230 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
2.0.0p353 :001 > require 'date' | |
=> true | |
2.0.0p353 :002 > date_str = "Mon., Feb. 10, 8 p.m" | |
=> "Mon., Feb. 10, 8 p.m" | |
2.0.0p353 :003 > DateTime.strptime(date_str, "%a., %b. %e, %l %P") | |
ArgumentError: invalid date | |
from (irb):3:in `strptime' | |
from (irb):3 | |
from /Users/johno/.rvm/rubies/ruby-2.0.0-p353/bin/irb:12:in `<main>' | |
2.0.0p353 :004 > DateTime.strptime(date_str, "%a., %b. %e,") | |
=> #<DateTime: 2014-02-10T00:00:00+00:00 ((2456699j,0s,0n),+0s,2299161j)> | |
2.0.0p353 :005 > d = DateTime.strptime(date_str, "%a., %b. %e,") | |
=> #<DateTime: 2014-02-10T00:00:00+00:00 ((2456699j,0s,0n),+0s,2299161j)> | |
2.0.0p353 :006 > d.day | |
=> 10 | |
2.0.0p353 :007 > d.month | |
=> 2 | |
2.0.0p353 :008 > d.hour | |
=> 0 | |
2.0.0p353 :009 > |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~|||$ irb | |
2.0.0p353 :001 > require 'date' | |
=> true | |
2.0.0p353 :002 > date_str = "Mon., Feb. 10, 8 p.m" | |
=> "Mon., Feb. 10, 8 p.m" | |
2.0.0p353 :003 > d = DateTime.strptime(date_str.split(/./).join(''), "%a, %b %e, %l %P") | |
ArgumentError: invalid date | |
from (irb):3:in `strptime' | |
from (irb):3 | |
from /Users/johno/.rvm/rubies/ruby-2.0.0-p353/bin/irb:12:in `<main>' | |
2.0.0p353 :004 > d = DateTime.strptime(date_str.split('.').join(''), "%a, %b %e, %l %P") | |
=> #<DateTime: 2014-02-10T20:00:00+00:00 ((2456699j,72000s,0n),+0s,2299161j)> | |
2.0.0p353 :005 > d.hour | |
=> 20 | |
2.0.0p353 :006 > exit | |
~|||$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment