DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
RoR Date Formats
From http://hittingthebuffers.com/2006/08/11/date-formats/:
August 11, 2006
Date formats
Here's a handy date related tip I just read when I was looking around for ways to make an RSS feed valid.
If you go to a command line and run script/console, then type ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS it displays a hash containing default date formatting which can be used with to_s() like this:
xml.pubDate(article.created_at.to_s(:rfc822))
It's also possible to add additional formats to the end of application.rb:
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
:default => "%m/%d/%Y",
:date_time12 => "%m/%d/%Y %I:%M%p",
:date_time24 => "%m/%d/%Y %H:%M"
)
From Comments (as of 2006.08.14):
2.
My personal faves:
:iso_8601_date_only => ‘%Y-%m-%d’,
:iso_8601_time_only => ‘%H:%M:%S%z’
Comment by Todd Sayre — August 12, 2006 @ 3:19 pm





Comments
Snippets Manager replied on Mon, 2009/12/28 - 4:50am
Snippets Manager replied on Mon, 2012/05/07 - 2:26pm
:date_slider_raw => '%Y%m%dT00:00:00', :date_slider_clean => '%a. %B %d'Snippets Manager replied on Wed, 2006/04/12 - 5:42pm