问题
I'm using the last build of date-fr-FR.js in the svn trunk (rev 191). The parsing seems to fail on days and months names.
Date.parse("9 3 2012")
is ok, but:
Date.parse("vendredi 9 mars 2012")
returns null.
parseExact doesn't help either:
Date.parseExact("vendredi 9 mars 2012", "dddd d MMMM yyyy")
returns null.
Anyone faced a similar issue ? Is there a more recent version of the localized files ?
Maybe you could recommend me another javascript date library if nobody can find a solution.
回答1:
The French culture file fr-FR:js appears to have a few of bugs. For example the regular expression for Friday shows:
/^ve(n(.(dredi)?)?)?/i
This means than either "ve" or "ven" or "ven." or "ven.dredi" are recognized as Friday but not "vendredi". More precisely the above regex matches the "vend" and leaves "redi" unmatched, thus failing the parser. The same bug is present for all days of the week and most months.
To fix this you could replace the above regular expression with:
/^ve(n(\.|(dredi)?)?)?/i
Adding the alternate "|" after the any character ".". I have also escaped the dot because it should not match "any" character but just the dot though this would not fail your test case.
来源:https://stackoverflow.com/questions/9632928/date-js-parseexact-with-french-culture