本文介绍了如何将美国日期格式转换为欧洲格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
来自: 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:
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.
或
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.
这篇关于如何将美国日期格式转换为欧洲格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!