如何将美国日期格式转换为欧洲格式
问题描述:
来自: 2011年5月19日
to: 2011-05- 19
当它发现它不能像 5/40/2011时,我需要它来引发错误
等。是否有任何库可以做得好?
I need it to raise an error when it finds that it cannot be real like 5/40/2011
etc. Are there any libraries that do it well?
答
Datejs是一个开源日期怎么样?图书馆?具体来说:
How about Datejs an open source date library? Specifically:
http: //code.google.com/p/datejs/wiki/APIDocumentation#parseExact
Date.parseExact("10/15/2004", "M/d/yyyy"); // The Date of 15-Oct-2004
Date.parse("15-Oct-2004", "d-MMM-yyyy"); // The Date of 15-Oct-2004
Date.parse("2004.10.15", "yyyy.MM.dd"); // The Date of 15-Oct-2004
Date.parseExact("10/15/2004", ["M/d/yyyy", "MMMM d, yyyy"]); // The Date of 15-Oct-2004
返回值
{日期}日期如果字符串无法转换为日期,则为null或null。
Return Value {Date} A Date object or null if the string cannot be converted into a Date.
或
http://code.google.com/p/datejs/wiki/APIDocumentation#validateDay
Date.validateDay(15, 2007, 1); // true, 15-Feb-2007
Date.validateDay(31, 2007, 10); // false, throws RangeError exception
返回值
{Boolean}如果在范围内,则为true否则是假的。
Return Value {Boolean} true if within range, otherwise false.