{"id":3831,"date":"2022-12-21T16:14:45","date_gmt":"2022-12-21T07:14:45","guid":{"rendered":"https:\/\/engineering.webstudio168.jp\/?p=3831"},"modified":"2026-06-30T21:25:55","modified_gmt":"2026-06-30T12:25:55","slug":"countdown-timer-js","status":"publish","type":"post","link":"https:\/\/engineering.webstudio168.jp\/blog\/countdown-timer-js\/","title":{"rendered":"\u6765\u5e74\uff082027\u5e74\uff09\u307e\u3067\u3042\u3068\u4f55\u65e5\uff1f\u4f55\u6642\u9593\uff1f\u4f55\u5206\uff1f\u4f55\u79d2\uff1f\u3010\u30ab\u30a6\u30f3\u30c8\u30c0\u30a6\u30f3\u30bf\u30a4\u30de\u30fcJavascript\u3011"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u4eca\u5e74\uff082026\u5e74\uff09\u3082\u30ab\u30a6\u30f3\u30c8\u30c0\u30a6\u30f3\u30bf\u30a4\u30de\u30fc\u3092\u3064\u304f\u308a\u307e\u3057\u305f\u306e\u3067\u3054\u67fb\u53ce\u304f\u3060\u3055\u3044\u3002<br><span class=\"red\">\u203b2023\/10\/27 \u8ffd\u8a18\uff1a\u3059\u307f\u307e\u305b\u3093\u3001JS\u306b\u30a8\u30e9\u30fc\u304c\u3042\u308a\u8868\u793a\u3055\u308c\u306a\u3044\u72b6\u614b\u3067\u3057\u305f\u3002\u4fee\u6b63\u3057\u3066\u304a\u304d\u307e\u3057\u305f\u3002<\/span><\/p>\n\n\n\n<p>2027\u5e7401\u670801\u65e500:00\u307e\u3067\u3042\u3068\u3001<span id=\"coundown01\"><\/span><\/p>\n<script>\nlet nowTime = new Date();\nlet limitTime = new Date(nowTime.getFullYear() + 1, 0, 1, 0, 0, 0);\n\nfunction CountdownTimer(elemID, timeLimit) {\n  this.initialize.apply(this, arguments);\n}\nCountdownTimer.prototype =   {\n\n  initialize: function(elemID, timeLimit) {\n    this.elem = document.getElementById(elemID);\n    this.timeLimit = timeLimit;\n  },\n  \n  countDown : function()  {\n    let timer = \"\";\n    let today = new Date();\n    let days = Math.floor((this.timeLimit - today) \/ (24 * 60 * 60 * 1000));\n    let hours = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) \/ (60 * 60 * 1000));\n    let mins = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) \/ (60 * 1000)) % 60;\n    let secs = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) \/ 1000) % 60 % 60;\n    let milis = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) \/ 10) % 100;\n    let me = this;\n        \n    if(this.elem!=null){\n      if((this.timeLimit - today) > 0){\n        if(days>0){\n          timer =  '<span class=\"num\">' + days + '<\/span>\u65e5';\n        }\n        if(hours>0){\n          timer = timer + '<span class=\"num\">' + this.addZero(hours) + '<\/span>\u6642\u9593';\n        }\n        timer =  timer + '<span class=\"num\">' + this.addZero(mins) +  '<\/span>\u5206<span class=\"num\">' + this.addZero(secs) + '<\/span>\u79d2'  + '<span class=\"num\">' + this.addZero(milis) + '<\/span>';\n        this.elem.innerHTML = timer;\n        tid = setTimeout(function() { me.countDown(); }, 10);\n      }else{\n        return;\n      }\n    }\n  },\n\n  addZero : function(num)  {\n    num = '00' + num;\n    str = num.substring(num.length - 2, num.length);\n    return str ;\n  }\n}\nlet timer01 = new CountdownTimer(\"coundown01\", limitTime); \ntimer01.countDown();\n<\/script>\n<style>\n.num {\n  font-size: 200%;\n}\n<\/style>\n\n\n\n<p>2027\u5e7401\u670801\u65e500:00\u307e\u3067\u3042\u3068\u3001<span id=\"coundown02\"><\/span><\/p>\n<script>\nfunction CountdownTimerHour(elemID, timeLimit) {\n  this.initialize.apply(this, arguments);\n}\nCountdownTimerHour.prototype =   {\n\n  initialize: function(elemID, timeLimit) {\n    this.elem = document.getElementById(elemID);\n    this.timeLimit = timeLimit;\n  },\n  \n  countDown : function()  {\n    let  timer = \"\";\n    let  today = new Date();\n    let  days = Math.floor((this.timeLimit - today) \/ (24 * 60 * 60 * 1000));\n    let  hours = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) \/ (60 * 60 * 1000));\n    let  mins = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) \/ (60 * 1000)) % 60;\n    let  secs = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) \/ 1000) % 60 % 60;\n    let  milis = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) \/ 10) % 100;\n    let  me = this;\n        \n    if(this.elem!=null){\n      if((this.timeLimit - today) > 0){\n        if(days>0){\n          hours = hours + (days * 24);\n        }\n        if(hours>0){\n          timer = timer + '<span class=\"num\">' + hours + '<\/span>\u6642\u9593';\n        }\n        timer =  timer + '<span class=\"num\">' + this.addZero(mins) +  '<\/span>\u5206<span class=\"num\">' + this.addZero(secs) + '<\/span>\u79d2'  + '<span class=\"num\">' + this.addZero(milis) + '<\/span>';\n        this.elem.innerHTML = timer;\n        tid = setTimeout(function() { me.countDown(); }, 10);\n      }else{\n        return;\n      }\n    }\n  },\n\n  addZero : function(num)  {\n    num = '00' + num;\n    str = num.substring(num.length - 2, num.length);\n    return str ;\n  }\n}\nlet timer02 = new CountdownTimerHour(\"coundown02\", limitTime); \ntimer02.countDown();\n<\/script>\n\n\n\n<p>2027\u5e7401\u670801\u65e500:00\u307e\u3067\u3042\u3068\u3001<span id=\"coundown03\"><\/span><\/p>\n<script>\nfunction CountdownTimerMinute(elemID, timeLimit) {\n  this.initialize.apply(this, arguments);\n}\nCountdownTimerMinute.prototype =   {\n\n  initialize: function(elemID, timeLimit) {\n    this.elem = document.getElementById(elemID);\n    this.timeLimit = timeLimit;\n  },\n  \n  countDown : function()  {\n    let  timer = \"\";\n    let  today = new Date();\n    let  days = Math.floor((this.timeLimit - today) \/ (24 * 60 * 60 * 1000));\n    let  hours = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) \/ (60 * 60 * 1000));\n    let  mins = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) \/ (60 * 1000)) % 60;\n    let  secs = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) \/ 1000) % 60 % 60;\n    let  milis = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) \/ 10) % 100;\n    let  me = this;\n        \n    if(this.elem!=null){\n      if((this.timeLimit - today) > 0){\n        if(days>0){\n          mins = (days*24*60) + mins;\n        }\n        if(hours>0){\n         mins = (hours*60) + mins;\n        }\n        timer =  timer + '<span class=\"num\">' + mins +  '<\/span>\u5206<span class=\"num\">' + this.addZero(secs) + '<\/span>\u79d2'  + '<span class=\"num\">' + this.addZero(milis) + '<\/span>';\n        this.elem.innerHTML = timer;\n        tid = setTimeout(function() { me.countDown(); }, 10);\n      }else{\n        return;\n      }\n    }\n  },\n\n  addZero : function(num)  {\n    num = '00' + num;\n    str = num.substring(num.length - 2, num.length);\n    return str ;\n  }\n}\nlet timer03 = new CountdownTimerMinute(\"coundown03\", limitTime); \ntimer03.countDown();\n<\/script>\n\n\n\n<p>2027\u5e7401\u670801\u65e500:00\u307e\u3067\u3042\u3068\u3001<span id=\"coundown04\"><\/span><\/p>\n<script>\nfunction CountdownTimerSeconds(elemID, timeLimit) {\n  this.initialize.apply(this, arguments);\n}\n\nCountdownTimerSeconds.prototype = {\n  initialize: function(elemID, timeLimit) {\n    this.elem = document.getElementById(elemID);\n    this.timeLimit = timeLimit;\n  },\n\n  countDown: function() {\n    let today = new Date();\n    let timeDiff = this.timeLimit - today;\n    let totalSecs = Math.floor(timeDiff \/ 1000);\n    let milis = Math.floor((timeDiff % 1000) \/ 10);\n    let timer = \"\";\n    let me = this;\n\n    if (this.elem != null) {\n      if (timeDiff > 0) {\n        timer = '<span class=\"num\">' + totalSecs + '<\/span>\u79d2' +\n                '<span class=\"num\">' + this.addZero(milis) + '<\/span>';\n        this.elem.innerHTML = timer;\n        setTimeout(function() { me.countDown(); }, 10);\n      } else {\n        this.elem.innerHTML = \"\u7d42\u4e86\u3057\u307e\u3057\u305f\";\n      }\n    }\n  },\n\n  addZero: function(num) {\n    return num < 10 ? '0' + num : num;\n  }\n};\n\nconst timer04 = new CountdownTimerSeconds(\"coundown04\", limitTime);\ntimer04.countDown();\n<\/script>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u306bJavaScript\u306e\u30b3\u30fc\u30c9\u3092\u63b2\u8f09\u3057\u3066\u304a\u304d\u307e\u3059\u306e\u3067\u304a\u4f7f\u3044\u304f\u3060\u3055\u3044\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-js\" data-file=\"countdown-timer.js\" data-lang=\"JavaScript\"><code>const nowTime = new Date();\nconst limitTime = new Date(nowTime.getFullYear() + 1, 0, 1, 0, 0, 0);\n\nfunction CountdownTimer(elemID, timeLimit) {\n  this.initialize.apply(this, arguments);\n}\nCountdownTimer.prototype =   {\n\n  initialize: function(elemID, timeLimit) {\n    this.elem = document.getElementById(elemID);\n    this.timeLimit = timeLimit;\n  },\n  \n  countDown : function()  {\n    let  timer = &quot;&quot;;\n    let  today = new Date();\n    let  days = Math.floor((this.timeLimit - today) \/ (24 * 60 * 60 * 1000));\n    let  hours = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) \/ (60 * 60 * 1000));\n    let  mins = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) \/ (60 * 1000)) % 60;\n    let  secs = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) \/ 1000) % 60 % 60;\n    let  milis = Math.floor(((this.timeLimit - today) % (24 * 60 * 60 * 1000)) \/ 10) % 100;\n    let  me = this;\n        \n    if(this.elem!=null){\n      if((this.timeLimit - today) &gt; 0){\n        if(days&gt;0){\n          timer =  &#39;&lt;span class=&quot;num&quot;&gt;&#39; + days + &#39;&lt;\/span&gt;\u65e5&#39;;\n        }\n        if(hours&gt;0){\n          timer = timer + &#39;&lt;span class=&quot;num&quot;&gt;&#39; + this.addZero(hours) + &#39;&lt;\/span&gt;\u6642\u9593&#39;;\n        }\n        timer =  timer + &#39;&lt;span class=&quot;num&quot;&gt;&#39; + this.addZero(mins) +  &#39;&lt;\/span&gt;\u5206&lt;span class=&quot;num&quot;&gt;&#39; + this.addZero(secs) + &#39;&lt;\/span&gt;\u79d2&#39;  + &#39;&lt;span class=&quot;num&quot;&gt;&#39; + this.addZero(milis) + &#39;&lt;\/span&gt;&#39;;\n        this.elem.innerHTML = timer;\n        tid = setTimeout(function() { me.countDown(); }, 10);\n      }else{\n        return;\n      }\n    }\n  },\n\n  addZero : function(num)  {\n    num = &#39;00&#39; + num;\n    str = num.substring(num.length - 2, num.length);\n    return str ;\n  }\n}\nconst timer01 = new CountdownTimer(&quot;coundown01&quot;, limitTime); \ntimer01.countDown();<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-html\" data-file=\"countdown-timer.html\" data-lang=\"HTML\"><code>&lt;p&gt;2026\u5e7401\u670801\u65e500:00\u307e\u3067\u3042\u3068\u3001&lt;span id=&quot;coundown01&quot;&gt;&lt;\/span&gt;&lt;\/p&gt;<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism undefined-numbers lang-css\" data-file=\"countdown-timer.css\" data-lang=\"CSS\"><code>.num {\n  font-size: 200%;\n}<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u5e74\uff082026\u5e74\uff09\u3082\u30ab\u30a6\u30f3\u30c8\u30c0\u30a6\u30f3\u30bf\u30a4\u30de\u30fc\u3092\u3064\u304f\u308a\u307e\u3057\u305f\u306e\u3067\u3054\u67fb\u53ce\u304f\u3060\u3055\u3044\u3002\u203b2023\/10\/27 \u8ffd\u8a18\uff1a\u3059\u307f\u307e\u305b\u3093\u3001JS\u306b\u30a8\u30e9\u30fc\u304c\u3042\u308a\u8868\u793a\u3055\u308c\u306a\u3044\u72b6\u614b\u3067\u3057\u305f\u3002\u4fee\u6b63\u3057\u3066\u304a\u304d\u307e\u3057\u305f\u3002 2027\u5e7401\u670801\u65e500:00\u307e\u3067\u3042 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3857,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55,43],"tags":[8,39],"class_list":["post-3831","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","category-43","tag-javascript","tag-39"],"_links":{"self":[{"href":"https:\/\/engineering.webstudio168.jp\/blog\/wp-json\/wp\/v2\/posts\/3831","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/engineering.webstudio168.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/engineering.webstudio168.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/engineering.webstudio168.jp\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/engineering.webstudio168.jp\/blog\/wp-json\/wp\/v2\/comments?post=3831"}],"version-history":[{"count":49,"href":"https:\/\/engineering.webstudio168.jp\/blog\/wp-json\/wp\/v2\/posts\/3831\/revisions"}],"predecessor-version":[{"id":7820,"href":"https:\/\/engineering.webstudio168.jp\/blog\/wp-json\/wp\/v2\/posts\/3831\/revisions\/7820"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/engineering.webstudio168.jp\/blog\/wp-json\/wp\/v2\/media\/3857"}],"wp:attachment":[{"href":"https:\/\/engineering.webstudio168.jp\/blog\/wp-json\/wp\/v2\/media?parent=3831"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/engineering.webstudio168.jp\/blog\/wp-json\/wp\/v2\/categories?post=3831"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/engineering.webstudio168.jp\/blog\/wp-json\/wp\/v2\/tags?post=3831"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}