5
1

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

Javascriptを用いたカウントダウンタイマー

5
Last updated at Posted at 2019-06-17

未来電子テクノロジーでインターンをしている小栗です。
プログラミング初心者であるため、内容に誤りがあるかもしれません。
もし、誤りがあれば修正するのでどんどん指摘してください。

2021年の四月までを期限とし、社会に出るまでに、できることをしようという内容で作成しました。

countdowntimer
          
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
          function countdowntimer(){//関数名を指定
           var countdown = setTimeout(function(){
            var today = new Date();//今日の日時を取得
            var targetDay = new Date('2021/04/01 00:00:00');//期限となる日時を秒まで指定
            var daysBetween = Math.ceil((targetDay - today) / (24*60*60*1000));//Math.ceil(引数として与えた数より大きい数以上の最小の整数を取得) 24時間*60日*60秒*1000で
            var remainDay = (targetDay - today);//残りの日数
            if (remainDay >= 0){
             var h = Math.floor(remainDay / 3600000);//Math.floor(引数として与えた数以下の最大の整数を与える。)
             var h1 = h % 24;
             var m = Math.floor((remainDay - h * 3600000) / 60000);
             var s = Math.round((remainDay - h * 3600000 - m * 60000) / 1000);
             $("#countdown").text("社会人まで"+ daysBetween + "日と" + h1 + "時間" + m + "分" +s + "秒です。");         if ((h == 0) && (m == 0) && (s == 0)) {//指定の日時が来たら、
               clearTimeout(countdown);
               $("#countdown").text("社会に出る時間です。覚悟はいいですか?");
               }
             }else{
               $("#countdown").text("社会人として活躍中です。");
             }
           }, 1000);
          }
       
          countdowntimer();
       
          
5
1
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
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?