View Full Version : Live Clock - Javascript

06-11-2007, 04: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";

second = "0"+second;

minute = "0"+minute;

ampm = "AM";

ampm = "PM"

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


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


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.

06-11-2007, 06: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

06-11-2007, 06: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.