0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

毎日、日が変わったときに画面更新

Posted at

毎日、日が変わったときに画面更新する処理を入れたときのメモです。

  const date_now = new Date();
  const date_refresh = new Date();

  date_refresh.setDate(date_now.getDate() + 1);
  date_refresh.setHours(0);
  date_refresh.setMinutes(0);
  date_refresh.setSeconds(0);
  //現在から更新時刻までの時間(ms)
  const time_refresh = date_refresh.getTime() - date_now.getTime();

  useEffect(() => {
    const id_refresh = setTimeout(function () {
      window.location.reload();
    }, time_refresh);

    return () => {clearTimeout(id_refresh);};
  }, [time_refresh]);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?