RoR Date Formats
Join the DZone community and get the full member experience.
Join For FreeFrom 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
Opinions expressed by DZone contributors are their own.
Comments