Node cron, run every midnight

前端 未结 5 1742
粉色の甜心
粉色の甜心 2020-12-17 11:03

I want to run cron job daily at midnight. For this I am using

0 0 0 1-31 * * 

but it doesn\'t work for me. I am using the node cron. Plea

5条回答
  •  孤城傲影
    2020-12-17 11:19

    You can try this format too.

    var CronJob=require('cron').CronJob;
    var cronJob1 = new CronJob({
    
        cronTime: '00 00 00 * * * ',
        onTick: function () {
        //Your code that is to be executed on every midnight
        },
        start: true,
        runOnInit: false
    });
    

    To understanding something more about cronTime, See the following codes:

    cronTime: '00 */3 * * * * ' => Executes in every 3 seconds.

    cronTime: '* */1 * * * * ' => MEANING LESS. Executes every one second.

    cronTime: '00 */1 * * * * ' => Executes every 1 minute.

    cronTime: '00 30 11 * * 0-5 ' => Runs every weekday (Monday to Friday) @ 11.30 AM

    cronTime: '00 56 17 * * * ' => Will execute on every 5:56 PM

提交回复
热议问题