Ognjen Regoje bio photo

Ognjen Regoje
But you can call me Oggy


I make things that run on the web (mostly).
More ABOUT me and my PROJECTS.

me@ognjen.io LinkedIn

Consistent display of dates in Rails

#rails #strftime #technical

In order to consistently display dates in a Rails application the strftime format can be set globally.

#config/initializers/time_formats.rb

Date::DATE_FORMATS[:default] = "%d/%m/%Y"
Time::DATE_FORMATS[:default] = "%d/%m/%Y"

This makes the default .to_s of a DateTime to use strftime("%d/%m/%Y").