944,038 Members | Top Members by Rank

Ad:
-1

Display the live time.

by on Apr 18th, 2007
Diplays the exact current time and date
HTML and CSS Code Snippet (Toggle Plain Text)
  1. <body onLoad="goforit()">
  2.  
  3.  
  4.  
  5. <script>
  6.  
  7. /*
  8. Live Date Script-
  9. © Dynamic Drive (www.dynamicdrive.com)
  10. For full source code, installation instructions, 100's more DHTML scripts, and Terms Of Use,
  11. visit http://www.dynamicdrive.com
  12. */
  13.  
  14.  
  15. var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
  16. var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
  17.  
  18. function getthedate(){
  19. var mydate=new Date()
  20. var year=mydate.getYear()
  21. if (year < 1000)
  22. year+=1900
  23. var day=mydate.getDay()
  24. var month=mydate.getMonth()
  25. var daym=mydate.getDate()
  26. if (daym<10)
  27. daym="0"+daym
  28. var hours=mydate.getHours()
  29. var minutes=mydate.getMinutes()
  30. var seconds=mydate.getSeconds()
  31. var dn="AM"
  32. if (hours>=12)
  33. dn="PM"
  34. if (hours>12){
  35. hours=hours-12
  36. }
  37. if (hours==0)
  38. hours=12
  39. if (minutes<=9)
  40. minutes="0"+minutes
  41. if (seconds<=9)
  42. seconds="0"+seconds
  43. //change font size here
  44. var cdate="<small> <font color='000000' face='Arial'> <b> "+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn
  45. +"</b> </font> </small> "
  46. if (document.all)
  47. document.all.clock.innerHTML=cdate
  48. else if (document.getElementById)
  49. document.getElementById("clock").innerHTML=cdate
  50. else
  51. document.write(cdate)
  52. }
  53. if (!document.all&&!document.getElementById)
  54. getthedate()
  55. function goforit(){
  56. if (document.all||document.getElementById)
  57. setInterval("getthedate()",1000)
  58. }
  59.  
  60. </script>
  61. <span id="clock"></span>
Comments on this Code Snippet
Dec 28th, 2008
0

Re: Display the live time.

thank you
Newbie Poster
uringinteristi is offline Offline
17 posts
since Dec 2008
Message:
Previous Thread in HTML and CSS Forum Timeline: i am new
Next Thread in HTML and CSS Forum Timeline: My flash drop down menu is not working please help.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC