...

View Full Version : Live Clock - Javascript



codethisdb
06-11-2007, 03:55 AM
I am using a script from hotscripts.com that uses javascript to display a live updating digital style clock.

Here is the javascript code that generates the data:



<script type="text/javascript">

function live_clock()
{
var today = new Date();
var second = today.getSeconds();
var minute = today.getMinutes();
var hour = today.getHours();
var hour24 = today.getHours();
var ampm = "";
var zone = today.

var day = today.getDay();
var date = today.getDate();
var month = today.getMonth();
var year = today.getFullYear();

var days = new Array();
days[0] = "Sunday";
days[1] = "Monday";
days[2] = "Tuesday";
days[3] = "Wednesday";
days[4] = "Thursday";
days[5] = "Friday";
days[6] = "Saturday";

var mns = new Array();
mns[0] = "January";
mns[1] = "February";
mns[2] = "March";
mns[3] = "April";
mns[4] = "May";
mns[5] = "June";
mns[6] = "July";
mns[7] = "August";
mns[8] = "September";
mns[9] = "October";
mns[10] = "November";
mns[11] = "December";

if(second<10)
{
second = "0"+second;
}

if(minute<10)
{
minute = "0"+minute;
}

if(hour24<=12)
{
ampm = "AM";
}

else
{
ampm = "PM"
}

if(hour24>=12 && hour24>=13)
{
hour= hour-12;
}

if(hour24==0)
{
hour=12;
}

document.getElementById('live_clock').innerHTML=(days[day]+', '+date+' '+mns[month]+' '+year+' '+hour+":"+minute+":"+second+' '+ampm+' PST');

}
</script>


I store that code in a seperate file and require it through php:



<?php require_once('includes/clock.php'); ?>


Then I place a div inside the page wherever I want the clock to display using:



<div id="live_clock" name="live_clock" class="date">&nbsp;</div>



Works fine in Firefox however not showing up in IE 6.0, the example on site works but not in my page.

rwedge
06-11-2007, 05:34 AM
This line is incomplete and does IE in and should cause an error in FF
var zone = today.since you do not use 'zone' any where in your script you do not need it

codethisdb
06-11-2007, 05:04 PM
Proof read for the win! I guess just because it works in Firefox doesn't mean the code is all good :) That was an easy one to spot, I apologize.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum