javascript - Dealing with date in different language using datapicker and moments -


i have web site which, depending on location, allows set date in different language:

example:

mercredi, juin 06, 2012 // french wednesday, jun 06, 2012 // english 

then these dates needs saved on 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 fix issue when user using different language english?

p.s.:
not sure if can helps...
momentsjs possible set lang in way, problem persists:

moment.lang('fr'); moment('mercredi, juin 06, 2012').format(); // nan-nan-nantnan:nan:nan+00:00 

there 2 things missing:

  1. load appropriate language file.

  2. to quote docu: "you can create moment string can parsed date.parse" [moment(string)] or "if know format of input string, can use parse moment" [moment(string, string)]. so, if isn't understood date.parse need give date format second argument.

this should work then:

moment.lang("fr"); moment('mercredi, juin 06, 2012', "dddd, mmmm dd, yyyy").format(); 

also see jsfiddle


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -