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

RoR Date Formats (See related posts)

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 on this post

blissdev posts on Sep 20, 2006 at 20:35
I get an error with that. What datatype are you using in the database.
sporkyy posts on Sep 24, 2006 at 15:39
If you use the Measure Map date slider here are a couple more you might find useful:
:date_slider_raw => '%Y%m%dT00:00:00',
:date_slider_clean => '%a. %B %d'

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts