{"id":9088,"date":"2021-10-26T22:41:59","date_gmt":"2021-10-26T19:41:59","guid":{"rendered":"https:\/\/elzero.org\/?p=9088"},"modified":"2022-09-28T18:20:13","modified_gmt":"2022-09-28T15:20:13","slug":"tutorials-create-countdown-timer","status":"publish","type":"post","link":"https:\/\/elzero.org\/old\/tutorials-create-countdown-timer\/","title":{"rendered":"Create Countdown Timer"},"content":{"rendered":"<h3>\u0627\u0644 Code<\/h3>\r\n\r\n<script type=\"text\/plain\" class=\"language-html\">\r\n<span class=\"days\"><\/span>\r\n<span class=\"hours\"><\/span>\r\n<span class=\"minutes\"><\/span>\r\n<span class=\"seconds\"><\/span>\r\n<\/script>\r\n\r\n<script type=\"text\/plain\" class=\"language-css\">\r\n* {\r\n  box-sizing: border-box;\r\n}\r\nbody {\r\n  font-family: \"Trebuchet MS\", \"Lucida Sans Unicode\", sans-serif;\r\n  margin: 0;\r\n}\r\n<\/script>\r\n\r\n<script type=\"text\/plain\" class=\"language-javascript\">\r\n\/\/ The End Of The Year Date To Countdown To\r\n\/\/ 1000 milliseconds = 1 Second\r\n\r\nlet countDownDate = new Date(\"Dec 31, 2021 23:59:59\").getTime();\r\n\/\/ console.log(countDownDate);\r\n\r\nlet counter = setInterval(() => {\r\n  \/\/ Get Date Now\r\n  let dateNow = new Date().getTime();\r\n\r\n  \/\/ Find The Date Difference Between Now And Countdown Date\r\n  let dateDiff = countDownDate - dateNow;\r\n\r\n  \/\/ Get Time Units\r\n  \/\/ let days = Math.floor(dateDiff \/ 1000 \/ 60 \/ 60 \/ 24);\r\n  let days = Math.floor(dateDiff \/ (1000 * 60 * 60 * 24));\r\n  let hours = Math.floor((dateDiff % (1000 * 60 * 60 * 24)) \/ (1000 * 60 * 60));\r\n  let minutes = Math.floor((dateDiff % (1000 * 60 * 60)) \/ (1000 * 60));\r\n  let seconds = Math.floor((dateDiff % (1000 * 60)) \/ 1000);\r\n\r\n  document.querySelector(\".days\").innerHTML = days < 10 ? `0${days}` : days;\r\n  document.querySelector(\".hours\").innerHTML = hours < 10 ? `0${hours}` : hours;\r\n  document.querySelector(\".minutes\").innerHTML = minutes < 10 ? `0${minutes}` : minutes;\r\n  document.querySelector(\".seconds\").innerHTML = seconds < 10 ? `0${seconds}` : seconds;\r\n\r\n  if (dateDiff < 0) {\r\n    clearInterval(counter);\r\n  }\r\n}, 1000);\r\n\r\n<\/script>","protected":false},"excerpt":{"rendered":"<p>\u0627\u0644 Code<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[879],"tags":[],"class_list":["post-9088","post","type-post","status-publish","format-standard","hentry","category-front-end-tutorials"],"_links":{"self":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/9088","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/comments?post=9088"}],"version-history":[{"count":1,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/9088\/revisions"}],"predecessor-version":[{"id":9090,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/posts\/9088\/revisions\/9090"}],"wp:attachment":[{"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/media?parent=9088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/categories?post=9088"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elzero.org\/old\/wp-json\/wp\/v2\/tags?post=9088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}