{"id":107,"date":"2011-12-08T07:44:50","date_gmt":"2011-12-08T15:44:50","guid":{"rendered":"http:\/\/shanelabs.com\/blog\/?p=107"},"modified":"2011-12-15T21:49:13","modified_gmt":"2011-12-16T05:49:13","slug":"end-of-the-day-countdown-in-javascript","status":"publish","type":"post","link":"https:\/\/shanelabs.com\/blog\/2011\/12\/08\/end-of-the-day-countdown-in-javascript\/","title":{"rendered":"End of the day countdown in javascript"},"content":{"rendered":"<p>Here&#8217;s how to have a realtime display showing how many hours, minutes, and seconds are left in the day:<\/p>\n<pre>Time left until midnight: &lt;span id='HMSremaining'&gt;&lt;\/span&gt;<\/pre>\n<pre>&lt;script&gt;\r\nfunction calculateHMSleft()\r\n{\r\n\t\/\/calculate\r\n\tvar now = new Date();\r\n\tvar hoursleft = 23-now.getHours();\r\n\tvar minutesleft = 59-now.getMinutes();\r\n\tvar secondsleft = 59-now.getSeconds();\r\n\r\n\t\/\/format 0 prefixes\r\n\tif(minutesleft&lt;10) minutesleft = \"0\"+minutesleft;\r\n\tif(secondsleft&lt;10) secondsleft = \"0\"+secondsleft;\r\n\r\n\t\/\/display\r\n\t$('#HMSremaining').html(hoursleft+\":\"+minutesleft+\":\"+secondsleft);\r\n}\r\n\r\ncalculateHMSleft();\r\nsetInterval(calculateHMSleft, 1000);\r\n&lt;\/script&gt;<\/pre>\n<p>If you calculate how many days until an event, then you can append that and have a countdown timer to any holiday or special\u00a0occasion!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s how to have a realtime display showing how many hours, minutes, and seconds are left in the day: Time left until midnight: &lt;span id=&#8217;HMSremaining&#8217;&gt;&lt;\/span&gt; &lt;script&gt; function calculateHMSleft() { \/\/calculate var now = new Date(); var hoursleft = 23-now.getHours(); var minutesleft = 59-now.getMinutes(); var secondsleft = 59-now.getSeconds(); \/\/format 0 prefixes if(minutesleft&lt;10) minutesleft = &#8220;0&#8221;+minutesleft; if(secondsleft&lt;10) [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-107","post","type-post","status-publish","format-standard","hentry","category-software","category-web"],"_links":{"self":[{"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/posts\/107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/comments?post=107"}],"version-history":[{"count":5,"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/posts\/107\/revisions"}],"predecessor-version":[{"id":133,"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/posts\/107\/revisions\/133"}],"wp:attachment":[{"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/media?parent=107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/categories?post=107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shanelabs.com\/blog\/wp-json\/wp\/v2\/tags?post=107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}