0

I want to execute a script at a specific time. How do I get something like this to work?

var future = moment().add('1', 'm').format()
if (moment().format() == future) {console.log('Whatsapp')}
  • Does this answer your question? https://stackoverflow.com/questions/21284312/moment-js-check-if-a-date-is-today-or-in-the-future – Jeremy Thille Jun 04 '21 at 07:39

1 Answers1

0

Get the time difference between now and the specific time in the future. Set a timeout:

const future = moment().add('5', 's');
const now = moment();
setTimeout(() => { console.log('Whatsapp'); }, future.diff(now));
<script src="https://cdn.jsdelivr.net/npm/moment@2.29.1/moment.min.js"></script>