0

I am trying to change a time of an event I pulled from Facebook which comes in a hash with time as a string. eg:

"fbevents" =>
{
"event1" => "2013-04-27T08:00:00-0400"
"event2" => "2013-04-27"
}

While using method strftime on the time, it won't allow it because it is a string. I want to change it to format: Day name, Month name, Year, time.

1

1 Answer 1

1

You can parse a string to create a Date. There are two methods that may be of use: parse and _parse. The first one creates a Date, the second one returns a hash of separated date values.

Date.parse "2013-04-27T08:00:00-0400"
=> Sat, 27 Apr 2013
Date._parse "2013-04-27T08:00:00-0400"
=> {:zone=>"-0400", :hour=>8, :min=>0, :sec=>0, :year=>2013, :mon=>4, :mday=>27, :offset=>-14400}

Use the first one if you're just looking to create a new Date instance. Use the second if you want to grab specific parts of the date to do other things with.

3
  • Hey I tried that and it worked in terminal through rails console but did not work in the app. Just shows: 2013-04-30 Commented Apr 28, 2013 at 4:03
  • It's also not responding to .to_datetime Commented Apr 28, 2013 at 4:10
  • Got it working! I actually had to do .to_time.strftime("%A, %B %d, %Y at %l:%M%p"). I guess this is specific to pulling start times for Facebook events. Thanks for all the help Tim! Commented Apr 28, 2013 at 4:14

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.