8

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
4

1 回答 1

5

缺少两件事:

  1. 加载适当的语言文件

  2. 引用文档:“您可以从可由 Date.parse 解析的字符串创建时刻”[moment(String)] 或“如果您知道输入字符串的格式,则可以使用它来解析时刻" [时刻(字符串,字符串)]。因此,如果 Date.parse 不理解,则需要将日期格式作为第二个参数。

这应该可以工作:

moment.lang("fr");
moment('Mercredi, Juin 06, 2012', "dddd, MMMM DD, YYYY").format();

也看到这个jsFiddle

于 2012-06-05T20:38:05.910 回答