I have a web site which, depending on the location, allows to set the date in different language:
Example:
Mercredi, Juin 06, 2012 // french
Wednesday, Jun 06, 2012 // english
Then these dates needs to be saved on the server using momentjs
moment('Tuesday, Jun 05, 2012').format(); // 2012-06-05T00:00:00+02:00
moment('Mercredi, Juin 06, 2012').format(); // NaN-NaN-NaNTNaN:NaN:NaN+00:00
How can I fix this issue when the user is using a different language from the english?
P.S.:
Not sure if it can helps...
with momentsjs is possible to set the lang in this way, but the problem persists:
moment.lang('fr');
moment('Mercredi, Juin 06, 2012').format(); // NaN-NaN-NaNTNaN:NaN:NaN+00:00
Edit file "bootstrap-datepicker.js" to add your languages: Show activity on this post. Download Language wise all datepicker files from here: [https://github.com/jquery/jquery-ui/tree/master/ui/i18n][1] I hope it will work.
There are two things missing:
load the appropriate language file.
To quote from the docu: "You can create a moment from a string that can be parsed by Date.parse" [moment(String)] or "If you know the format of an input string, you can use that to parse a moment" [moment(String, String)]. So, if it isn't understood by Date.parse you need to give the date format as a second argument.
This should work then:
moment.lang("fr");
moment('Mercredi, Juin 06, 2012', "dddd, MMMM DD, YYYY").format();
also see this jsFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With