Javascript Date.parse help

前端 未结 3 1769
孤独总比滥情好
孤独总比滥情好 2021-01-19 23:42

I am using Javascript Date.parse() to check if a start time is after an end time.

The time in question is like this:

Date.parse("12:0         


        
3条回答
  •  既然无缘
    2021-01-20 00:17

    You can not just pass a time to Date.parse(), as it is expecting a datestring. If you flip the > in your code to a <, you'll notice it still returns false. This is because Date.parse() is returning NaN.

    Try this:

    var a = new Date("January 1, 1970 12:00:00");
    var b = new Date("January 1, 1970 21:30:00");
    
    if (a > b) { alert(true); } else { alert(false); }
    if (a < b) { alert(true); } else { alert(false); }
    

提交回复
热议问题