Javascript Javascript如何检查日期是否大于或等于日期值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37485744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 20:23:04 来源:igfitidea点击:
Javascript how to check if a date is greater than or equal to a date value
提问by Mattlinux1
I'm currently trying to see if the date value is set to today's date or greater.
我目前正在尝试查看日期值是否设置为今天的日期或更大的日期。
var date = document.getElementById("inputDate").value;
var varDate = new Date(date); //dd-mm-YYYY
var today = new Date();
if(varDate >= today) {
//Do something..
alert("Working!");
}
Date format dd-mm-YYYY
日期格式 dd-mm-YYYY
The current code above won't work.
上面的当前代码将不起作用。
回答by gurvinder372
If you only want to compare Dateand not Date-Timethen add this line
如果您只想比较日期而不是日期时间,请添加此行
var today = new Date();
today.setHours(0,0,0,0);
before comparison.
对比前。