Click to See Complete Forum and Search --> : jvscrpt clock


poumpoum
12-03-2002, 01:51 PM
how can i build a javascript clock displayin words instead of numbers without usin gif images??

AdamGundry
12-03-2002, 04:13 PM
I take it you already understand how you can find the current time using JavaScript - if not, check out this page (http://developer.netscape.com/docs/manuals/communicator/jsref/core3.htm).

You will probably need to create an array for time strings, like this (because hours range from 0-23, loop through twice:

var hourtext = new Array("zero","one","two", ... ,"eleven");

You could then find the current hour as a string like this:

var NowDate = new Date()
var Str = hourtext[NowDate.getHours] + " o'clock.";

I.e. at 12 noon Str will be "twelve o'clock", at 11pm "eleven o'clock", but between midnight and one am "zero o'clock".

Obviously this will need some work based on how you want the time to display.

Once you have the string you want (presumably using Date.getMinutes as well), assign it to a <div> using:

div_id.innerHTML = Str;

Hope this helps

Adam