Advertisement
ekostadinov

Show Time Now

Mar 10th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Powered by JavaScript
  2.     <style>
  3.         #timer, #controls {
  4.             margin: 15px auto;
  5.             width: 400px;
  6.                         border-radius: 20px;
  7.             text-align: center;
  8.         }
  9.  
  10.         #timer {
  11.             font-size: 56px;
  12.             border: 1px solid black;
  13.                         color: #442C14;
  14.                         background-color: #ff8866;
  15.         }
  16.  
  17.         a {
  18.             color: black;
  19.             text-decoration: none;
  20.         }
  21.  
  22.             a:hover {
  23.                 text-decoration: underline;
  24.             }
  25.     </style>
  26.     <script>
  27.         var timer;
  28.         function startTimer() {
  29.             timer = setInterval(setTime, 1000);
  30.         }
  31.         function stopTimer() {
  32.             clearInterval(timer);
  33.         }
  34.                 function viewCode(){
  35. myWindow=window.open('','','width=200,height=200, menubar=yes,status=yes, resizable=yes');
  36. myWindow.document.write("<p>This is 'myWindow'</p>");
  37. myWindow.focus();
  38.                 }
  39.     </script>
  40.  
  41.  
  42.     <div id="timer">
  43.     </div>
  44.     <div id="controls">
  45.         <a href="#" onclick="startTimer()">Start timer</a>
  46.         <a href="#" onclick="stopTimer()">Stop timer</a>
  47.                 <a href="#" onclick="viewCode()">View my code</a>
  48.     </div>
  49.     <script>
  50.         function setTime() {
  51.             var time = new Date();
  52.             var hours = time.getHours();
  53.             if (hours < 10) {
  54.                 hours = "0" + hours;
  55.             }
  56.             var minutes = time.getMinutes();
  57.             if (minutes < 10) {
  58.                 minutes = "0" + minutes;
  59.             }
  60.             var seconds = time.getSeconds();
  61.             if (seconds < 10) {
  62.                 seconds = "0" + seconds;
  63.             }
  64.             document.getElementById("timer").innerHTML = hours + " : " + minutes + " : " + seconds;
  65.         }
  66.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement