Digital Clock Using Jquery

Language
In this tutorial I am going to teach how on to create a digital clock that you can use in your systems or project. Just download the source code below for basis. and follow the instructions.

DIRECTIONS

INCLUDE THIS LINK IN YOUR HEAD TAG

CSS CODE

  1. <style type="text/css">
  2. body{
  3.          background:#f5f5f5;
  4.          font:bold 12px Arial, Helvetica, sans-serif;
  5.          margin:0;
  6.          padding:0;
  7.          min-width:960px;
  8.          color:#000;
  9. }
  10.  
  11. a {
  12.         text-decoration:none;
  13.         color:darkblue;
  14. }
  15.  
  16. h1 {
  17.         font: 4em normal Arial, Helvetica, sans-serif;
  18.         padding: 20px;  margin: 0;
  19.         text-align:center;
  20. }
  21.  
  22. h1 small{
  23.         font: 0.2em normal  Arial, Helvetica, sans-serif;
  24.         text-transform:uppercase; letter-spacing: 0.2em; line-height: 5em;
  25.         display: block;
  26. }
  27.  
  28. h2 {
  29.     font-weight:700;
  30.     color:#bbb;
  31.     font-size:20px;
  32. }
  33.  
  34. h2, p {
  35.         margin-bottom:10px;
  36. }
  37.  
  38. @font-face {
  39.     font-family: 'BebasNeueRegular';
  40.     src: url('BebasNeue-webfont.eot');
  41.     src: url('BebasNeue-webfont.eot?#iefix') format('embedded-opentype'),
  42.          url('BebasNeue-webfont.woff') format('woff'),
  43.          url('BebasNeue-webfont.ttf') format('truetype'),
  44.          url('BebasNeue-webfont.svg#BebasNeueRegular') format('svg');
  45.     font-weight: normal;
  46.     font-style: normal;
  47.  
  48. }
  49.  
  50. .container {width: 960px; margin: 0 auto; overflow: hidden;}
  51.  
  52. .clock {width:800px; margin:0 auto; padding:30px; color:#fff; }
  53.  
  54. #Date { font-family:'BebasNeueRegular', Arial, Helvetica, sans-serif; font-size:36px; text-align:center; text-shadow:0 0 5px darkblue; }
  55.  
  56. ul { width:800px; margin:0 auto; padding:0px; list-style:none; text-align:center; }
  57. ul li { display:inline; font-size:10em; text-align:center; font-family:'BebasNeueRegular', Arial, Helvetica, sans-serif; text-shadow:0 0 5px darkblue; }
  58.  
  59. #point { position:relative; -moz-animation:mymove 1s ease infinite; -webkit-animation:mymove 1s ease infinite; padding-left:10px; padding-right:10px; }
  60.  
  61. @-webkit-keyframes mymove
  62. {
  63. 0% {opacity:1.0; text-shadow:0 0 20px darkblue;}
  64. 50% {opacity:0; text-shadow:none; }
  65. 100% {opacity:1.0; text-shadow:0 0 20px darkblue; }    
  66. }
  67.  
  68.  
  69. @-moz-keyframes mymove
  70. {
  71. 0% {opacity:1.0; text-shadow:0 0 20px #00c6ff;}
  72. 50% {opacity:0; text-shadow:none; }
  73. 100% {opacity:1.0; text-shadow:0 0 20px #00c6ff; }     
  74. }
  75.  
  76. </style>

JAVASCRIPTS

  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. // Create two variable with the names of the months and days in an array
  4. var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
  5. var dayNames= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
  6.  
  7. // Create a newDate() object
  8. var newDate = new Date();
  9. // Extract the current date from Date object
  10. newDate.setDate(newDate.getDate());
  11. // Output the day, date, month and year    
  12. $('#Date').html(dayNames[newDate.getDay()] + " " + newDate.getDate() + ' ' + monthNames[newDate.getMonth()] + ' ' + newDate.getFullYear());
  13.  
  14. setInterval( function() {
  15.         // Create a newDate() object and extract the seconds of the current time on the visitor's
  16.         var seconds = new Date().getSeconds();
  17.         // Add a leading zero to seconds value
  18.         $("#sec").html(( seconds < 10 ? "0" : "" ) + seconds);
  19.         },1000);
  20.        
  21. setInterval( function() {
  22.         // Create a newDate() object and extract the minutes of the current time on the visitor's
  23.         var minutes = new Date().getMinutes();
  24.         // Add a leading zero to the minutes value
  25.         $("#min").html(( minutes < 10 ? "0" : "" ) + minutes);
  26.     },1000);
  27.        
  28. setInterval( function() {
  29.         // Create a newDate() object and extract the hours of the current time on the visitor's
  30.         var hours = new Date().getHours();
  31.         // Add a leading zero to the hours value
  32.         $("#hours").html(( hours < 10 ? "0" : "" ) + hours);
  33.     }, 1000);
  34.        
  35. });
  36. </script>

HTML CODE

  1. <h1>Digital Clock Using Jquery<small> <a href="http://www.sourcecodester.com/">www.sourcecodester.com</a></small></h1>
  2. <div class="container">
  3. <div class="clock">
  4. <div id="Date"></div>
  5.  
  6. <ul>
  7.         <li id="hours"> </li>
  8.     <li id="point">:</li>
  9.     <li id="min"> </li>
  10.     <li id="point">:</li>
  11.     <li id="sec"> </li>
  12. </ul>
  13.  
  14. </div>
  15. </div>
  16. </body>

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment