Skip to content Skip to sidebar Skip to footer

Chrome Extension: Detecting New Day (day Changed) In Javascript?

I know there's not a event listener for a new day (or hour/minute, for that matter). But in my Chrome Extension, I need to know when a new day has started, and which means I'll hav

Solution 1:

If you mean a new day for the user, you can set a single timeout when the page loads.

functionsetnewdaytimer(){
    if(window.newdaytimer) clearTimeout(newdaytimer);
    var now= newDate,
    tomorrow= newDate(now.getFullYear(), now.getMonth(), now.getDate()+1); 
    window.newdaytimer= setTimeout(newdayalarm, tomorrow-now);
}
functionnewdayalarm(){
    alert((newDate()).toLocaleTimeString());
}

window.onload=setnewdaytimer;

Solution 2:

Depending how exact you want to be, the only way doing this is by setting an interval. You can set your precision to be whatever you want. 1min 5min 10min

Post a Comment for "Chrome Extension: Detecting New Day (day Changed) In Javascript?"