How to run a function at specific time & date?

前端 未结 5 1483
日久生厌
日久生厌 2020-12-02 17:40

How can I run a function at a given time and date?

Example: I have a function that needs to run on the 12th of each month at 10AM.

This page will be running

5条回答
  •  伪装坚强ぢ
    2020-12-02 18:21

    You can use something like this

    var runned = false;
    var d = new Date();
    if(d.getDate() == 12 && d.getHours() == 10 && !runned){
        //Do some magic
        runned = true;
    }
    

    If you want some with the minute (and not the whole hour you can add d.getMinutes()

提交回复
热议问题