0% found this document useful (0 votes)
12 views2 pages

Dynamic JavaScript Date and Time Script

This document contains JavaScript code to dynamically display the current date and time on a web page. It uses functions to get the current date, hour, minute, second and day values. Conditional statements format the values and assign them to an input field, which is then refreshed every second to continuously update the displayed time.

Uploaded by

vtnithya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Dynamic JavaScript Date and Time Script

This document contains JavaScript code to dynamically display the current date and time on a web page. It uses functions to get the current date, hour, minute, second and day values. Conditional statements format the values and assign them to an input field, which is then refreshed every second to continuously update the displayed time.

Uploaded by

vtnithya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Sample Code java script for dynamic date time

1. <div class='widget-content'>
2.  
3. <script language="JavaScript">
4. <!--
5.  
6. function startclock()
7. {
8. var thetime=new Date();
9.  
10. var nhours=[Link]();
11. var nmins=[Link]();
12. var nsecn=[Link]();
13. var nday=[Link]();
14. var nmonth=[Link]();
15. var ntoday=[Link]();
16. var nyear=[Link]();
17. var AorP=" ";
18.  
19. if (nhours>=12)
20.     AorP="P.M.";
21. else
22.     AorP="A.M.";
23.  
24. if (nhours>=13)
25.     nhours-=12;
26.  
27. if (nhours==0)
28.    nhours=12;
29.  
30. if (nsecn<10)
31.  nsecn="0"+nsecn;
32.  
33. if (nmins<10)
34.  nmins="0"+nmins;
35.  
36. if (nday==0)
37.   nday="Sunday";
38. if (nday==1)
39.   nday="Monday";
40. if (nday==2)
41.   nday="Tuesday";
42. if (nday==3)
43.   nday="Wednesday";
44. if (nday==4)
45.   nday="Thursday";
46. if (nday==5)
47.   nday="Friday";
48. if (nday==6)
49.   nday="Saturday";
50.  
51. nmonth+=1;
52.  
53. if (nyear<=99)
54.   nyear= "19"+nyear;
55.  
56. if ((nyear>99) && (nyear<2000))
57.  nyear+=1900;
58.  
59. [Link]=nday+",
"+nmonth+"/"+ntoday+"/"+nyear+" "+nhours+": "+nmins+":
"+nsecn+" "+AorP;
60.  
61. setTimeout('startclock()',1000);
62.  
63. }
64.  
65. //-->
66. </script>
67.  
68.  
69.  
70.  
71. <form name="clockform">
72.         <input name="clockspot" size="30"
type="text"/>
73.  
74. </form>
75. <script language="JavaScript">
76. <!--
77. startclock();
78. //-->
79. </script>
80.  
81. </div>
82.  

You might also like