How to specify Moscow time or server time in request auto-sending using JS?

  • 0
    Hello!
    At that time, I wrote a JS code that automatically clicks the button after 60 seconds from the moment it was launched.
    Here:
    setTimeout(() => {
      document.querySelector("input.button.solid").click();
    }, 60000);

    As far as I understand, the time here goes from the time that is installed on my computer, on which the browser is running. Tell me, how can I specify server time instead, or Moscow time? You just need super high accuracy. If you need to redo the code for this, please tell me how to write it. I do not understand programming and wrote all this, collecting pieces of information from various forums. I can't go further.
    Thank you all for your help.
    JavaScript Anonymous, Feb 3, 2020

  • 2 Answers
  • 0
    What is Ultra High Accuracy? Accurate to the second?

    How to find the remaining time in setTimeout?

    Sets the timer to an "exact" interval. Accuracy is achieved by the fact that the function is called once a second (the interval is configurable) and adjusts the time remaining before the event. Actual accuracy depends on the load on the computer at the time of the timer.

    To fire at the right time, you need to specify this time in the format with a time zone.

    function setMyTimer(_t, interval){
    if(typeof(_t)=='function'){
    _t={main:_t}
    }
    _t.start=Date.now();
    _t.interval=_t.interval||interval;
    _t.log_interval=_t.log_interval || 1000;

    function log(){
    const diff=_t.interval - (Date.now() - _t.start);
    if(_t.log)_t.log(diff);
    if(diff>_t.log_interval)
    setTimeout(log,_t.log_interval);
    else {
    setTimeout(_t.main,diff<0?1:diff);
    }
    }

    setTimeout(log,_t.log_interval);
    }

    let AlertTime=new Date('2020-11-18T10:39:00+03:00') ;

    setMyTimer(()=>alert('Доставка!'), AlertTime.valueOf()-Date.now());
    Anonymous

  • 0
    This is done like this, setInterval () is set to check the current time, let's say every hour, when there are several hours left before the appointed date, we change the check interval and already check the date every minute. In a few minutes, we begin to check the time every second and a few seconds before the required time, we roll out setTimeout () with the exact number of milliseconds to run your command at the exact specified time.
    Willow Shah

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!