简体   繁体   中英

How to get and updated date in luxon without re executing the code?

So my problem is that i want to sent something in a certain hour using a discord bot. Then i have luxon, i already done all the code, but looks like luxon gets the date when i execute the code, for example if it is 2021-01-29-03-20-11 (YY-MM-DD-HH-mm-SS) and i want to execute something when it is 2021-01-29-03-21-11 (YY-MM-DD-HH-mm-SS), then i should execute the code in that exact moment, i can't update or didn't find a way to update the date with out re-executing the code.

I tried to set the var where i declare a new date into an interval but didn't worked:

const timeDateInterval = setInterval(() => {
    let interval = DateTime.local().setZone('America/Bogota').toFormat('HHmmss');
    return interval;
}, 1000);

Then i would console log it:

console.log(timeDateInterval);

And i get a time out error (or i think it is an error):

    Timeout {
  _idleTimeout: 1000,
  _idlePrev: [TimersList],
  _idleNext: [TimersList],
  _idleStart: 91,
  _onTimeout: [Function (anonymous)],
  _timerArgs: undefined,
  _repeat: 1000,
  _destroyed: false,
  [Symbol(refed)]: true,
  [Symbol(kHasPrimitive)]: false,
  [Symbol(asyncId)]: 7,
  [Symbol(triggerId)]: 0
}

So is there a way to get and updated date in luxon with out re-executing the code?. Or some how re execute the code but without turning off the discord bot?

The "interval" that you set is just a date. I don't think that is what you want. You need to calculate how long the duration of the interval is. Luxon can calculate intervals for you, but your question indicates you just want 1 minute which is 60*1000. Also, the setInterval call back does not have a return value. It actually needs to do something (presumably send a discord message). Here is a really basic example of using setInterval to get you started. Once you see how it works, you can replace the 1000 with 60*1000 for the 1 minute you said you wanted.

 const timeDateInterval = setInterval(() => { const time = new Date; console.log(time.toString()); }, 1000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM