JAVASCRIPT   63

digiclock

Guest on 6th July 2022 09:12:51 AM

  1. // JavaScript Document
  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. $('#Date').html(dayNames[newDate.getDay()] + " " + newDate.getDate() + ' ' + monthNames[newDate.getMonth()] );
  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. });

Raw Paste


Login or Register to edit or fork this paste. It's free.