Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>Digital Clock</title>
- </head>
- <body>
- <h1 id="clock">Clock</h1>
- <script type="text/javascript">
- function digitalClock(){
- var date = new Date();
- var hours = date.getHours() + '';
- var minutes = date.getMinutes() + '';
- var seconds = date.getSeconds() + '';
- var day = date.getDay();
- if(hours.length < 2){
- hours = '0' + hours;
- }
- if(minutes.length < 2){
- mintues = '0' + minutes;
- }
- if(seconds.length < 2){
- seconds = '0' + seconds;
- }
- var weekDays = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
- var clock = weekDays[day] + ' ' + hours + ':' + minutes + ':' + seconds;
- document.getElementById('clock').innerHTML = clock;
- console.log(clock);
- }
- digitalClock();
- setInterval(digitalClock,1000);
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement