Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title> Time </title>
- <script type="text/javascript" charset="utf-8">
- window.onload=init;
- function init(){
- startTime();
- }
- function startTime() {
- var greeting;
- var today=new Date();
- var h=today.getHours();
- var m=today.getMinutes();
- var s=today.getSeconds();
- m = checkTime(m);
- s = checkTime(s);
- if (h <= 12) {
- adj = 'am';
- h2 = h;
- greeting = "morning";
- }else{
- adj = 'pm';
- h2=h-12;
- if (h < 17) {
- greeting = "afternoon"
- }else{
- greeting = "evening"
- };
- };
- document.getElementById('clock').innerHTML = h2+":"+m+":"+s+" "+ adj; // Remove '":"+s+' if you dont want the seconds
- document.getElementById('clock24').innerHTML = h+":"+m+":"+s; // Remove '":"+s+' if you dont want the seconds
- document.getElementById('greeting').innerHTML = greeting;
- var t = setTimeout(function(){startTime()},500);
- };
- function checkTime(i) {
- if (i<10) {i = "0" + i}; // add zero in front of numbers < 10
- return i;
- };
- </script>
- </head>
- <body>
- <!-- 12 hr clock--><div id="clock"></div>
- <!-- 24 hr clock--><div id="clock24"></div>
- <!-- Greeting based on time of the day--><p>Good <span id="greeting"></span>, Anon</p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment