Never been to DZone Snippets before?

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

About this user

Matt Scilipoti

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

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
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS