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 3 years have passed since last update.

JavaScript タイマーの使い方

Last updated at Posted at 2020-06-06

タイマーの作り方

0.5秒ごとに表示を更新する


<div id="timer"></div>


<script>
let timer = () => {
    let now = new Date();
    document.getElementById('timer').innerHTML = `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`;
}

let timerId = setInterval(timer, 500);
</script>

時間になったら何かやらせたい場合

上のサンプルで10秒後に時間が変わる

let timerId = setTimeout(timer, 10*1000); 

上のタイマーを解除するには

clearTimeout(timerId)
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?