<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width, initial-scale=1.0"><title>Date & Time Dashboard</title><style>/* style.css */*{margin:0;padding:0;box-sizing:border-box;font-family:'Segoe UI',Tahoma,Geneva,Verdana,sans-serif;}body{background:linear-gradient(135deg,#1e3c72,#2a5298);height:100vh;display:flex;justify-content:center;align-items:center;color:white;}.container{text-align:center;background:rgba(255,255,255,0.1);padding:3rem;border-radius:20px;backdrop-filter:blur(10px);box-shadow:010px30pxrgba(0,0,0,0.3);width:90%;max-width:600px;}/* Greeting */.greeting{font-size:1.5rem;margin-bottom:1rem;color:#a8d0e6;text-transform:uppercase;letter-spacing:2px;}/* Clock */.time{font-size:5rem;font-weight:bold;text-shadow:2px2px10pxrgba(0,0,0,0.2);margin-bottom:0.5rem;}.date{font-size:1.2rem;color:#e0e0e0;margin-bottom:2rem;}/* Countdown */.countdown-container{border-top:1pxsolidrgba(255,255,255,0.2);padding-top:1.5rem;}.countdown-containerh3{margin-bottom:1rem;font-weight:400;}.countdown{display:flex;justify-content:center;gap:1.5rem;}.countdowndiv{display:flex;flex-direction:column;font-size:0.8rem;color:#ccc;}.countdownspan{font-size:2rem;font-weight:bold;color:#fff;}/* Alarm Styles */.alarm-container{border-top:1pxsolidrgba(255,255,255,0.2);margin-top:1.5rem;padding-top:1.5rem;}.alarm-inputs{display:flex;justify-content:center;gap:10px;margin:10px0;}input[type="time"]{padding:10px;border-radius:5px;border:none;font-size:1rem;background:rgba(255,255,255,0.9);}button{padding:10px20px;border-radius:5px;border:none;cursor:pointer;font-weight:bold;transition:background0.3s;}#set-alarm-btn{background-color:#4CAF50;/* Green */color:white;}#set-alarm-btn.active{background-color:#f44336;/* Red (for cancel) */}.alarm-status{font-size:0.9rem;color:#ffd700;height:1.2rem;/* Reserve space */}/* Stop Alarm Button (pulsing red) */.stop-btn{margin-top:15px;background-color:#ff0000;color:white;font-size:1.2rem;animation:pulse1sinfinite;}.hidden{display:none;}@keyframespulse{0%{transform:scale(1);}50%{transform:scale(1.05);}100%{transform:scale(1);}}</style></head><body><divclass="container"><divid="greeting"class="greeting">Loading...</div><divclass="clock-container"><divid="time"class="time">00:00:00</div><divid="date"class="date">Loading Date...</div></div><divclass="countdown-container"><h3>Countdown to New Year</h3><divid="countdown"class="countdown"><div><spanid="days">00</span> Days</div><div><spanid="hours">00</span> Hours</div><div><spanid="minutes">00</span> Mins</div><div><spanid="seconds">00</span> Secs</div></div></div><divclass="alarm-container"><h3>Set Alarm</h3><divclass="alarm-inputs"><inputtype="time"id="alarm-time-input"><buttonid="set-alarm-btn"onclick="toggleAlarm()">Set Alarm</button></div><divid="alarm-status"class="alarm-status">Alarm is OFF</div></div><buttonid="stop-alarm-btn"class="stop-btn hidden"onclick="stopAlarmSound()">STOP ALARM</button></div><script>// script.jsfunctionupdateDashboard(){constnow=newDate();// --- 1. CLOCK & DATE ---// Extract time componentslethours=now.getHours();constminutes=String(now.getMinutes()).padStart(2,'0');constseconds=String(now.getSeconds()).padStart(2,'0');// Determine AM/PM (Optional, remove if you want 24h format)// const ampm = hours >= 12 ? 'PM' : 'AM';// hours = hours % 12;// hours = hours ? hours : 12; // the hour '0' should be '12'// Format: HH:MM:SS// Note: Remove padStart if using AM/PM logic above for single digit hoursconsttimeString=`${String(hours).padStart(2,'0')}:${minutes}:${seconds}`;document.getElementById('time').textContent=timeString;// Date Format: Monday, October 2, 2023constoptions={weekday:'long',year:'numeric',month:'long',day:'numeric'};constdateString=now.toLocaleDateString('en-US',options);document.getElementById('date').textContent=dateString;// --- 2. DYNAMIC GREETING ---constgreetingElement=document.getElementById('greeting');consthour=now.getHours();if(hour<12){greetingElement.textContent="Good Morning";}elseif(hour<18){greetingElement.textContent="Good Afternoon";}else{greetingElement.textContent="Good Evening";}}functionupdateCountdown(){// --- 3. COUNTDOWN TO NEXT YEAR ---constcurrentYear=newDate().getFullYear();constnextYear=newDate(`January 1, ${currentYear+1} 00:00:00`);constcurrentTime=newDate();constdiff=nextYear-currentTime;constd=Math.floor(diff/1000/60/60/24);consth=Math.floor((diff/1000/60/60)%24);constm=Math.floor((diff/1000/60)%60);consts=Math.floor((diff/1000)%60);document.getElementById('days').textContent=d;document.getElementById('hours').textContent=String(h).padStart(2,'0');document.getElementById('minutes').textContent=String(m).padStart(2,'0');document.getElementById('seconds').textContent=String(s).padStart(2,'0');}// Update the clock immediately and then every secondsetInterval(updateDashboard,1000);setInterval(updateCountdown,1000);// Run once on load to avoid 1-second delayupdateDashboard();updateCountdown();// --- ALARM LOGIC ---letalarmTime=null;letalarmTimeout=null;letaudioCtx=null;letoscillator=null;letalarmInterval=null;// To repeat the beepfunctiontoggleAlarm(){constinput=document.getElementById('alarm-time-input');constbtn=document.getElementById('set-alarm-btn');conststatus=document.getElementById('alarm-status');if(alarmTime){// If alarm is already set, clear it (Cancel)alarmTime=null;btn.textContent="Set Alarm";btn.classList.remove('active');status.textContent="Alarm is OFF";stopAlarmSound();// Stop sound if it's currently ringing}else{// Set the alarmif(!input.value){alert("Please select a time first!");return;}alarmTime=input.value;btn.textContent="Cancel Alarm";btn.classList.add('active');status.textContent=`Alarm set for ${alarmTime}`;}}// Function to generate the "Beep" sound using Web Audio APIfunctionplayBeep(){// Create Audio Context only when needed (browsers require interaction)if(!audioCtx){audioCtx=new(window.AudioContext||window.webkitAudioContext)();}// Create an oscillator (the sound generator)oscillator=audioCtx.createOscillator();constgainNode=audioCtx.createGain();oscillator.type='square';// 'square' sounds more like an alarm than 'sine'oscillator.frequency.setValueAtTime(440,audioCtx.currentTime);// 440Hz (A4)// Connect parts: Oscillator -> Volume(Gain) -> Speakersoscillator.connect(gainNode);gainNode.connect(audioCtx.destination);// Play soundoscillator.start();}functionstartAlarmRinging(){conststopBtn=document.getElementById('stop-alarm-btn');stopBtn.classList.remove('hidden');// Show the big STOP button// Play a beep every 500msplayBeep();// Stop the individual beep after 200mssetTimeout(()=>{if(oscillator)oscillator.stop();},200);// Loop the beepalarmInterval=setInterval(()=>{playBeep();setTimeout(()=>{if(oscillator)oscillator.stop();},200);},500);}functionstopAlarmSound(){// Stop logicif(alarmInterval)clearInterval(alarmInterval);if(oscillator){try{oscillator.stop();}catch(e){}// Ignore error if already stopped}// Hide STOP button and resetdocument.getElementById('stop-alarm-btn').classList.add('hidden');// Optional: Auto-cancel the alarm logic so it doesn't ring tomorrowalarmTime=null;document.getElementById('set-alarm-btn').textContent="Set Alarm";document.getElementById('set-alarm-btn').classList.remove('active');document.getElementById('alarm-status').textContent="Alarm Cleared";}// --- INTEGRATE INTO EXISTING CLOCK LOOP ---// We need to check the alarm every second. // Add this check inside your existing updateDashboard() function, // OR simpler: just set a separate interval here.setInterval(()=>{if(alarmTime){constnow=newDate();// Format current time to HH:MM to match input valueconstcurrentHours=String(now.getHours()).padStart(2,'0');constcurrentMinutes=String(now.getMinutes()).padStart(2,'0');constcurrentTimeString=`${currentHours}:${currentMinutes}`;constcurrentSeconds=now.getSeconds();// Check if times match AND it is the 0th second (so it triggers once)if(currentTimeString===alarmTime&¤tSeconds===0){startAlarmRinging();}}},1000);</script></body></html>