Some of you have remarked that you like the Obama Countdown Clock on my home page. For those of you who would like to create your own, I give you the necessary code. These code snippets will print the time remaining in the Obama administration in the format: “1460d 23h 59m 59s”.
Note that the Obama failure will end with the inauguration of the next president, which is scheduled to occur on January 20, 2013, at 12 Noon, Eastern Standard Time. In computer system time, this is 1,358,701,200 (seconds since Jan 1, 1970, 00:00:00 UTC).
The first option, if you would like a static clock, is to create it using PHP. This clock is calculated by the web server, and will only be updated whenever the web page is reloaded.
<?php
$datearray=getdate();
$sectot=1358701200-$datearray[0];
$seconds=$sectot%60;
$mintot=floor($sectot/60);
$minutes=$mintot%60;
$hourtot=floor($mintot/60);
$hours=$hourtot%24;
$days=floor($hourtot/24);
echo($days);
echo("d ");
if ($hours<10) echo("0");
echo($hours);
echo("h ");
if ($minutes<10) echo("0");
echo($minutes);
echo("m ");
if ($seconds<10) echo("0");
echo($seconds);
echo("s");
?>
The second option, for a dynamic clock, is to create it using Javascript. This clock is calculated by the web browsing computing, and it will update the clock once per second.
First step, create a file called “obamacountdownclock.js”, containing the following function:
function obamaCountdownClock()
{
var now = new Date();
var tnow = now.getTime();
var msectot = 1358701200000-tnow;
var sectot = Math.ceil(msectot/1000);
var mintot = Math.floor(sectot/60);
var seconds = sectot%60;
var hourtot = Math.floor(mintot/60);
var minutes = mintot%60;
var days = Math.floor(hourtot/24);
var hours = hourtot%24;
if (hours<10) {hours="0"+hours};
if (minutes<10) {minutes="0"+minutes};
if (seconds<10) {seconds="0"+seconds};
document.getElementById('obamaclock').innerHTML = days+"d "+hours+"h "+minutes+"m "+seconds+"s";
t=setTimeout('obamaCountdownClock()',1000);
}
Next, in the head section of your html code, add the following line to load the previous javascript file:
<script type="text/javascript" src="obamacountdownclock.js"></script>
Finally, add the following text inside your html code, where you would like the clock to appear:
<span id="obamaclock"></span>
<script type="text/javascript">obamaCountdownClock()</script>
Enjoy!