如何阻止JavaScript Date构造函数接受无效日期? [英] How to prevent JavaScript Date Constructor from accepting invalid dates?
本文介绍了如何阻止JavaScript Date构造函数接受无效日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
新日期('02 / 31/2015');
成为
Tue Mar 03 2015 00:00:00 GMT-0500(EST)
对不起,这已经被问到,我不能/太愚蠢地找到它:)。
解决方案
我结束了使用 moment.js 。它具有其他Date对象增强功能之间的验证和溢出计算。感谢Kevin Williams为
I realize that this probably a feature, but I need the Date Constructor to bail on an invalid date not automagically roll it to the appropriate date. What is the best way to accomplish this?
new Date('02/31/2015');
becomes
Tue Mar 03 2015 00:00:00 GMT-0500 (EST)
Sorry if this has already been asked, I wasn't able to/am too stupid to find it :).
解决方案
I ended up using moment.js. It has validation and overflow calculations among other Date object enhancements. Thanks to Kevin Williams for
这篇关于如何阻止JavaScript Date构造函数接受无效日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文