time.js 901 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <!-- Hide
  2. var timerID = null
  3. var timerRunning = false
  4. function MakeArray(size)
  5. {
  6. this.length = size;
  7. for(var i = 1; i <= size; i++)
  8. {
  9. this[i] = "";
  10. }
  11. return this;
  12. }
  13. function stopclock (){
  14. if(timerRunning)
  15. clearTimeout(timerID);
  16. timerRunning = false
  17. }
  18. function showtime () {
  19. var now = new Date();
  20. var hours = now.getHours();
  21. var minutes = now.getMinutes();
  22. var seconds = now.getSeconds();
  23. var timeValue = "";
  24. timeValue += ((hours <= 12) ? hours : hours - 12);
  25. timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
  26. timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
  27. timeValue += (hours < 12) ? " AM" : " PM";
  28. document.jsfrm.face.value = timeValue;
  29. timerID = setTimeout("showtime()",1000);
  30. timerRunning = true
  31. }
  32. function startclock () {
  33. stopclock();
  34. showtime()
  35. }
  36. document.write("<form name='jsfrm'>")
  37. document.write("<input type=text name='face' value='' class=time>")
  38. document.write("</form>")
  39. //-->