ExtremeGamer1480

JavaScript Time Teller

Jun 6th, 2021
782
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function telltime() {
  2.     var hour = new Date().getHours(),
  3.         min = new Date().getMinutes(),
  4.         sec = new Date().getSeconds(),
  5.         month = new Date().getMonth() + 1,
  6.         day = new Date().getDate(),
  7.         year = new Date().getFullYear(),
  8.         ampm;
  9.  
  10.     switch (new Date().getDay()) {
  11.         case 0:
  12.             today = "Sunday";
  13.             break;
  14.         case 1:
  15.             today = "Monday";
  16.             break;
  17.         case 2:
  18.             today = "Tuesday";
  19.             break;
  20.         case 3:
  21.             today = "Wednesday";
  22.             break;
  23.         case 4:
  24.             today = "Thursday";
  25.             break;
  26.         case 5:
  27.             today = "Friday";
  28.             break;
  29.         case 6:
  30.             today = "Saturday";
  31.     }
  32.  
  33.     if (sec < 10) sec = `0${sec}`
  34.     if (min < 10) min = `0${min}`
  35.     if (hour > 12) {
  36.         ampm = 'PM';
  37.     } else {
  38.         ampm = 'AM';
  39.     }
  40.     if (hour > 12) hour -= 12
  41.  
  42.     alert(`The current time is:\n\n${month}/${day}/${year}\n${today} ${day}, ${year}\n${hour}:${min}:${sec} ${ampm} ${new Date().toString().slice(35,new Date().toString().length - 1)}`);
  43. }
  44. telltime();
RAW Paste Data