Advertisement
SyP-

JS APP CLOCK

Dec 29th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=, initial-scale=">
  7. <title>Clock</title>
  8. <style>
  9. body {
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. font-family: "Lato", sans-serif;
  14. }
  15. #clock {
  16. height: 100vh;
  17. width: 100%;
  18. background-color: #14080e;
  19. color: #e9eb9e;
  20. display: flex;
  21. align-items: center;
  22. justify-content: center;
  23. font-size: 50px;
  24. }
  25. </style>
  26. </head>
  27.  
  28. <body>
  29. <div style="text-aling: center">
  30. <h1>JS APP CLOCK</h1>
  31. </div>
  32. <div id="clock">
  33. </div>
  34. <script>
  35. function clock() {
  36. let date = new Date();
  37. let hrs = date.getHours();
  38. let mins = date.getMinutes();
  39. let secs = date.getSeconds();
  40. let period = "AM";
  41.  
  42. if (hrs == 0) hrs = 12;
  43. if (hrs > 12) {
  44. hrs = hrs - 12;
  45. period = "PM";
  46. }
  47.  
  48. hrs = hrs < 10 ? `0${hrs}` : hrs;
  49. mins = mins < 10 ? `0${mins}` : mins;
  50. secs = secs < 10 ? `0${secs}` : secs;
  51.  
  52. let time = `${hrs}:${mins}:${secs} ${period}`;
  53. setInterval(clock, 1000);
  54. document.getElementById("clock").innerText = time;
  55. }
  56.  
  57. clock();
  58.  
  59. </script>
  60. </body>
  61.  
  62. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement