简体   繁体   English

如何检查选择日期和今天的日期是相同的

[英]how to check picked date and todays date is equal

pickedDate = new Date(Date.parse(txtDate.value.replace(/-/g, ' ')));
todaysDate = new Date();
todaysDate.setHours(0, 0, 0, 0)
if (todaysDate == pickedDate)
{
    return true;
}
    else
{
    return false;
}

I'm checking if picked date and today's date are equal and then returning true if they're equal or false if they're not, but condition is always false when i run the code. 我正在检查选择日期和今天的日期是否相等然后如果它们相等则返回true或者如果它们不相等则返回false ,但是当我运行代码时条件总是假的。

Test the following condition: 测试以下条件:

if (todaysDate.getTime() == pickedDate.getTime())
{

This should test for equality, because the getTime() method returns the Unix time of the object (as an integer) which can be compared against each other. 这应测试相等性,因为getTime()方法返回对象的Unix时间(作为整数),可以相互比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM