Skip to content
Common date time formats for Rails applications
Ruby JavaScript
Find file
New pull request
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Almost every Rails project I start requires the use of custom formats for outputting Time. It's pretty trivial to add to a project, but I always forget the constant name for the initializer. It's Time::DATE_FORMATS. I inevitably have to google or look in previous projects. Not a big deal, but nonetheless, it's unnecessary.

This Gem provides some common formats as well allowing you to define your own in a date_time_formats.yml file.


Add this line to your application's Gemfile:

gem 'date_time_formats'

And then execute:

$ bundle

Or install it yourself as:

$ gem install date_time_formats


DateTimeFormats adds support for common formats on the "Time#to_s" method  # => 2012 # => 1/01/2012

DateTimeFormats comes with a default set of formats. You can define your own by adding a config/date_time_formats.yml file to your Rails app. The syntax is simple key value YAML.

# config/date_time_formats.yml
year_and_day: "%Y-%d"


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Something went wrong with that request. Please try again.