Detect current date change in JavaScript

I’m writing a calendar Web application and I’m highlighting current date on the calendar. I want to automatically update which date is highlighted when the actual date changes.

So basically I need a way to have a callback called on midnight. How is it possible? I can imagine naive solution which calculates milliseconds before midnight and calls setTimeout, but I’m not sure how reliable this solution is:

  1. What will happen if browser will put my tab into power-save mode? Will timeout be called after unfreezing the tab given the fact that it will happen after midnight and timeout will miss it’s original time?

  2. How to handle timezone/daylight saving changes?

I also can imagine another naive solution which just uses setInterval to have a callback called every second and continuously check current system date. I don’t like this approach, because it is power consuming and may make not happy mobile users.