[removed] IF time >= 9:30 then

前端 未结 8 2049
一整个雨季
一整个雨季 2020-12-30 11:25

I\'m trying to write a statement that says \"if time is this and less than that then\". I can use get hours and get min. However, I\'m having problems combining a time suc

8条回答
  •  生来不讨喜
    2020-12-30 11:46

    use new Date().getTime() returns milliseconds for much easier comparison. This way there is no need to check hour, min, second, millisecond. Fiddle link

    var d930 = new Date(2010, 12, 21, 9, 30, 0, 0), // today 9:30:00:000
        d931 = new Date(2010, 12, 21, 9, 31, 0, 0), // today 9:31:00:000
        t930 = d930.getTime(),
        t931 = d931.getTime();
    
    
    console.log(t931 > t930);
    

    This way your code can check against a static 9:30 time.

    var time930 = new Date(2010, 12, 21, 9, 30, 0, 0).getTime(),
        sunday = 0,
        now = new Date();
    
    if(now.getDay() == sunday && now.getTime() >= time930){
        /* do stuff */
    }
    

提交回复
热议问题