Javascript Clock **URGENT EASY 500 POINTS**

I need a javascript clock. I want it to display the time like this:

5:35pm April 4, 2006

but instead of getting the time and date from the user's computer I want to have it start at a date and time that I specify. Also I want it to count so on the page it is live and it isn't in a text box it is just plain text.

Max
LVL 4
TheMaximumWeaselAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LakioCommented:
<html>
<head>
<title>Lakio's Timemover</title>
<script>
var when = new Date('5:35pm April 4, 2006'); // just insert the date and time here

function clock(){
var mo=['January','February','March','April','May','June','July','August','September','October','November','December'];
var ap=when.getHours()?'pm ':'am ';
var ho=when.getHours(); ho=ho>12?ho-12:ho;

document.getElementById('clock').innerHTML=ho+when.toUTCString().match(/:\d\d/)+ap+mo[when.getMonth()]+' '+when.getDate()+', '+when.getUTCFullYear();

when=new Date(Date.parse(when)+60000);
}
</script>
</head>
<body onload="clock();self.setInterval('clock()', 60000);">
<div id="clock"></div>
</body>
</html>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Samuel LiewCommented:
Lakio's answer is OK, however I suggest that the time be updated every second instead:

<body onload="clock();self.setInterval('clock()', 1000);">
0
LakioCommented:
btw: its set for every min
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Samuel LiewCommented:
I know, but you want it to be accurate to the second...
0
LakioCommented:
if we are displaying min not sec we dont need that,

new Date('5:35pm April 4, 2006')
is the same as new Date(2006, 3, 4, 17, 35, 0, 0) (yr_num, mo_num, day_num , hr_num, min_num, sec_num, ms_num)
so sec are set a 0 ok!?

and sins the next min is after 60sec its no need to run the script 60times for nothing,
thats just becuse we dont show sec but if we did then we would run it every sec.

In short: It is accurate to the second
0
Samuel LiewCommented:
But the first time the script is run, the update will be between 60 secs to 119 seconds.
0
LakioCommented:
"But the first time the script is run, the update will be between 60 secs to 119 seconds."
I dont understand your point but here is a script that is very very accurate.

and still just runs every min

On page load the time is set to '5:35pm April 4, 2000' and it does not matter how often the script is run or if the cpu is under alot of load. the time is connected the the cpu clock so its alwas "running".


<html>
<head>
<title>Lakio's Timemover v2.0</title>
<script>
diff = new Date()-new Date('5:35pm April 4, 2000'); // just insert the date and time here
function clock(){var when=new Date(new Date()-diff);
var mo=['January','February','March','April','May','June','July','August','September','October','November','December'];
var ap=when.getHours()?'pm ':'am ';
var ho=when.getHours(); ho=ho>12?ho-12:ho;

document.getElementById('clock').innerHTML=ho+when.toUTCString().match(/:\d\d/)+ap+mo[when.getMonth()]+' '+when.getDate()+', '+when.getUTCFullYear();
}
</script>
</head>
<body onload="clock();self.setInterval('clock()', 60000);">
<div id="clock"></div>
</body>
</html>
0
Samuel LiewCommented:
ok, won't argue... cos it still generally works. It was just a suggestion in the first place.
0
TheMaximumWeaselAuthor Commented:
I already found one online and edited it for my  site so I will split all of the points to the people who provided an acceptable answer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.