Guest User

my clock on wordpress

a guest
Jan 13th, 2025
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. window.addEventListener("load", () => {
  2.   clock();
  3.   function clock() {
  4.     const today = new Date();
  5.      
  6.     // get time components
  7.     const hours = today.getHours();
  8.     const minutes = today.getMinutes();
  9.     const seconds = today.getSeconds();
  10.  
  11.     //add '0' to hour, minute & second when they are less 10
  12.     const hour = hours < 10 ? "0" + hours : hours;
  13.     const minute = minutes < 10 ? "0" + minutes : minutes;
  14.     const second = seconds < 10 ? "0" + seconds : seconds;
  15.  
  16.     //make clock a 12-hour time clock
  17.     const hourTime = hour > 24 ? hour - 24 : hour;
  18.  
  19.     if (hour < 18 ) {
  20.         Saluto = "☀️";
  21.     } else {
  22.         Saluto = "🌙 ";
  23.     }
  24.      
  25.     // if (hour === 0) {
  26.     //   hour = 12;
  27.     // }
  28.     //assigning 'am' or 'pm' to indicate time of the day
  29.     const ampm = hour < 12 ? "" : "";
  30.  
  31.     // get date components
  32.     const month = today.getMonth();
  33.     const day = today.getDate();
  34.    
  35.    
  36.     //declaring a list of all months in  a year
  37.     const monthList = [
  38.       "Gennaio",
  39.       "Febbraio",
  40.       "Marzo",
  41.       "Aprile",
  42.       "Maggio",
  43.       "Giugno",
  44.       "Luglio",
  45.       "Agosto",
  46.       "Settembre",
  47.       "Ottobre",
  48.       "Novembre",
  49.       "Decembre"
  50.     ];
  51.      
  52.     //get current date and time
  53.     const SpecificDate = new Date();  
  54.      
  55.     const date = Saluto + day + " " + monthList[month] + " ";
  56.     const time = hourTime + ":" + minute + ":" + second + ampm;
  57.  
  58.     //combine current date and time
  59.     const dateTime = date + time;
  60.  
  61.     //print current date and time to the DOM
  62.     document.getElementById("date-time").innerHTML = dateTime;
  63.     setTimeout(clock, 1000);
  64.   }
  65. });
  66.  
  67. // Function to open a popup and control its content and behavior
  68. function openInteractivePopup() {
  69.     // Open a new window with specific dimensions
  70.     let popup = window.open("", "InteractivePopupExample", "width=995,height=600");
  71.     // Write more complex and interactive content into the popup
  72.     popup.document.write(`
  73.         <iframe src="https://www.meteoeradar.it/radar-meteo?center=42.18,16.96&amp;zoom=5.51" name="CW2" scrolling="no" width="980" height="580" frameborder="0px" style="border: 0px solid #10658E;border-radius: 50px"></iframe>
  74.     `);
  75.     popup.document.close(); // Good practice to close the document stream
  76. }
Advertisement
Add Comment
Please, Sign In to add comment