my_record.created_at.strftime("%d-%b-%y")
but it is hardly descriptive.
So there are a couple of ways of getting dates to format as you want them in Rails. The first is to set your own key in the date format table, and select it explicitly.
Time::DATE_FORMATS[:uk] = "%d-%b-%y"
my_record.created_at.to_s(:uk)
But if you want this date format all the time, just overwrite the
:default key. Then to_s will use your format by default.Time::DATE_FORMATS[:default] = "%d-%b-%y"
my_record.created_at.to_s
I stick the command in the
ApplicationHelper. It's always a global change.
0 comments:
Post a Comment