RSS

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

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

 
2 Comments

Posted by on March 13, 2014 in Ruby on Rails

 

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

  1. julianrawcliffe

    March 28, 2014 at 1:35 pm

    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. Ruby Programming

    April 17, 2014 at 6:13 pm

    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: