Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strptime and I18n, how to parse a date for current language

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?

like image 555
Francesco Belladonna Avatar asked Jan 23 '13 16:01

Francesco Belladonna


1 Answers

I solved my problem in this way:

Date.strptime(params[:date], I18n.translate('date.formats.default'))
like image 101
Francesco Belladonna Avatar answered Nov 19 '22 23:11

Francesco Belladonna