Guest User

Horloge JS

a guest
Dec 9th, 2019
120
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let doc;
  2.  
  3. window.onload = function() {
  4. doc = document.getElementById('heure');
  5. doc.classList.add('heureCl')
  6. }
  7.  
  8. function update()
  9. {
  10. if (doc)
  11. {
  12. let date = new Date();
  13. let hr = date.getHours() < 10 ? "0"+ date.getHours() : date.getHours();
  14. let min = date.getMinutes() < 10 ? "0"+ date.getMinutes() : date.getMinutes();
  15. let sec = date.getSeconds() < 10 ? "0"+ date.getSeconds() : date.getSeconds();
  16. doc.innerHTML = hr + ":" + min + ":" + sec;
  17. }
  18. }
  19. window.setInterval(update, 1000);
RAW Paste Data