The momentjs library can output the remaining time to date:

var time = moment().add(2,'h'); setInterval(function(){ console.log(moment().to(time)); //"Через 2 часа" },1000); 

This line is displayed somewhere on the web page, how do you know when it will change?
Only manually, after each time, check how much is left and execute through this time:

 var time = moment().add(10,'m'); moment().diff(); disp(); function disp(){ console.log(moment().to(time)); setTimeout(disp,get_time()); } function get_time(){ var diff = time.diff(moment(), 'm'); if(diff > 60) return 3600000; //1 час else if(diff > 1) return 60000; //1 мин else return 10000; //10 сек } 
  • If more than an hour - update once per hour
  • If more than a minute - update once a minute.
  • If more than a second, update once per second.

Or are there more correct and simple solutions?

  • It is not entirely clear what you want. If more than a second, then more and hours, respectively. Just update once per second and that's it. Or specify the question - RussCoder

0