Time to tomorrow



  • There's a violin that's counting till tomorrow. Every line I wrote comments. I don't understand how the bul-in-a-minute is calculated: (seconds % 3600) / 60♪ And a second. (seconds % 3600) % 60

    var tomorrow = new Date().setHours(24, 0, 0);
    

    (function foo() {
    var now = new Date();

    // Сколько секунд осталось до завтра.
    var seconds = parseInt(tomorrow - now) / 1000;

    // 3600 - кол-во секунд в часе. Сколько часов осталось до завтра
    var hh = parseInt( seconds / 3600 );

    //
    var mm = parseInt( (seconds % 3600) / 60 );

    var ss = parseInt( (seconds % 3600) % 60 );

    document.body.innerHTML = hh + ":" + mm + ":" + ss ;

    setTimeout(foo, 1000);
    })();



  • https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#%D0%94%D0%B5%D0%BB%D0%B5%D0%BD%D0%B8%D0%B5_%D0%BF%D0%BE_%D0%BC%D0%BE%D0%B4%D1%83%D0%BB%D1%8E_() returns the balance of the separation. Thus the result

    seconds % 3600
    

    That's the number of seconds of the hour.

    here. (seconds % 3600) / 60 They're moving in minutes.

    Here. (seconds % 3600) % 60 the same principle shall be taken for a second of not a full minute.


    Example:

    Take an example seconds=4000

    In this case, one hour (3600) plus one hour less than 60 minutes

    seconds % 3600 = 4000 % 3600 = 400
    

    Let's see how long it takes minutes.

    400 / 60 = 6.666666666666667
    

    Let's drop the fragment, get six minutes.

    We need to know the number of seconds.

    400 % 60 = 40
    

    Total: 1 full hour, 6 full minutes, 40 seconds


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2