Reputation: 11729
I'm using strptime
to parse a date formatted in dd/mm/YYYY
format, however I just thought that simply parsing in this way will break i18n support, because if my customer is using a different language I will try to parse it in my format, while I want it to use date.formats.default
format in that function.
How to achieve this?
Upvotes: 8
Views: 2171
Reputation: 11729
I solved my problem in this way:
Date.strptime(params[:date], I18n.translate('date.formats.default'))
Upvotes: 20
Reputation: 781
If you are using Date or Time you can use .to_s to apply default format
Date.today.to_s
Time.now.to_s
Upvotes: 0