2 Comments

Formatting Time and Date in Ruby on Rails Using strftime()


2 comments on “Formatting Time and Date in Ruby on Rails Using strftime()

  1. A really neat way a really pushing decent date formatting into the application is to use an initializer, say, config/initializers/date_format.rb, with something like,

    Date::DATE_FORMATS.merge!(
    :my_date => lambda { |time| time.strftime(“#{ActiveSupport::Inflector.ordinalize(time.day)} %b %Y”) })
    and the following code i a view template,

    variable_name.date_field.to_s(:my_date)

    which can make it easier to get consistent formatting across the application instead of having to remember the strftime format used from one place to another.

  2. I am a beginner in field of development and I love ruby on rails programming and looking for learning resources and your post is very informative and useful in this case.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: