[removed] IF time >= 9:30 then

前端 未结 8 2086
一整个雨季
一整个雨季 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:36

    You have a few typos and basic javascript errors.
    Might wanna brush up on the basics.
    W3Schools is where I learned all I know. It works fine if you fix them...

    var now = new Date();
      var hour = now.getHours();
      var day = now.getDay();
      var minutes = now.getMinutes();
      if(day == 0 && hour == 9 && minutes < 30 && minutes > 10 || day == 0 && hour == 9)
          document.write('Time is between 9:10 and 9:30');
    

    Think of the if statement as basic logic.
    If the day is Sunday(0)
    AND the hour is 9
    AND the minutes are greater than 10 AND the minutes are less than 10 OR the day is Sunday(0)
    AND the hour is before 9.

提交回复
热议问题