|
|
| Web Design in a Nutshell (ISBN: 0596001967) |
 |
List Price: $29.95
Our Price: $20.97
Used Price: $5.95
Release Date: 15 October, 2001
Manufacturer: O'Reilly & Associates (Paperback)
Sales Rank: 2,444
Author: Jennifer Niederst
|
More Info
|
|
|
Javascript Display Current Time
|
2003-01-19 20:32:48
|
| |
html
|
|
|
|
|
Category: source:html:javascript
|
|
Description: Update the current time every second and print the value to an input box.
|
|
Platform: all
|
|
Author: detour
|
|
Viewed: 18475
|
|
Rating: 4.5/5 (113 votes)
|
|
|
| If you have any questions about
this piece of code or still need help, try posting your question on the forum. |
<html>
<script language="Javascript">
setInterval("settime()", 1000);
function settime () {
var curtime = new Date();
var curhour = curtime.getHours();
var curmin = curtime.getMinutes();
var cursec = curtime.getSeconds();
var time = "";
if(curhour == 0) curhour = 12;
time = (curhour > 12 ? curhour - 12 : curhour) + ":" +
(curmin < 10 ? "0" : "") + curmin + ":" +
(cursec < 10 ? "0" : "") + cursec + " " +
(curhour > 12 ? "PM" : "AM");
document.date.clock.value = time;
}
</script>
<body>
<form name="date">
<input type="text" name="clock" style="border: 0px" value="">
</form>
</body>
</html>
|
|
|