Agyan
adda
Run
Reset
Copy
JavaScript Tutorial › JS Dates › Live clock and days left
Back to tutorial
Code
Edit, then press Run or Ctrl+Enter
<h2 id="clock"></h2> <p id="today"></p> <p id="left"></p> <script> function tick() { const now = new Date(); document.getElementById('clock').textContent = now.toLocaleTimeString('en-IN'); document.getElementById('today').textContent = now.toLocaleDateString('en-IN', { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' }); const newYear = new Date(now.getFullYear() + 1, 0, 1); const days = Math.ceil((newYear - now) / (1000 * 60 * 60 * 24)); document.getElementById('left').textContent = days + ' days to New Year'; } tick(); setInterval(tick, 1000); </script>
Result