Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. var t = document.getElementById("currentTime");
  2.  
  3. function updateTime(){
  4. var currentTime = new Date();
  5. var hours = currentTime.getHours();
  6. var minutes = currentTime.getMinutes();
  7. var seconds = currentTime.getSeconds();
  8. // if hours is in the PM, make it non-military
  9. if(hours > 12){
  10. var d_hours = hours - 12;
  11. }
  12. // format the minutes
  13. if(minutes < 10){
  14. minutes = "0" + minutes;
  15. }
  16. // format the seconds
  17. if(seconds < 10){
  18. seconds = "0" + seconds;
  19. }
  20. // make the string
  21. var t_str = d_hours + ":" + minutes + ":" + seconds;
  22. // decide if AM or PM and update the string
  23. if(hours > 11 && hours < 17){
  24. t_str += " PM - Enjoy Your Afternoon!";
  25. } else if(hours <= 11){
  26. t_str += " AM - Enjoy Your Morning!";
  27. }else if(hours >= 17){
  28. t_str += " PM - Enjoy Your Evening!";
  29. }
  30.  
  31. t.innerHTML = t_str;
  32. }
  33.  
  34. updateTime(); // Called once so time updates as soon as the page loads
  35.  
  36. setInterval(updateTime, 1000); // set to update every 1 second after that
  37.  
  38. console.log("Clock Loaded!");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement