Skip to content

Instantly share code, notes, and snippets.

@fjfish
Created December 11, 2011 17:18
Show Gist options
  • Save fjfish/1461638 to your computer and use it in GitHub Desktop.
Save fjfish/1461638 to your computer and use it in GitHub Desktop.
Converting a JSON string date into a Ruby Time object
# Convert string of the form 2011-12-31T23:59:59+00:00 to a Ruby Time object
# I'm sure there's an easier way to do this.
def self.json_to_ruby_time(the_string)
string_elements = the_string.split /[-T:+]+/
string_elements.pop
Time.new *(string_elements.map(&:to_i))
end
@paulingham
Copy link

Heh, just gave him the same response on Facebook @cauis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment