Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var t = document.getElementById("currentTime");
- function updateTime(){
- var currentTime = new Date();
- var hours = currentTime.getHours();
- var minutes = currentTime.getMinutes();
- var seconds = currentTime.getSeconds();
- // if hours is in the PM, make it non-military
- if(hours > 12){
- var d_hours = hours - 12;
- }
- // format the minutes
- if(minutes < 10){
- minutes = "0" + minutes;
- }
- // format the seconds
- if(seconds < 10){
- seconds = "0" + seconds;
- }
- // make the string
- var t_str = d_hours + ":" + minutes + ":" + seconds;
- // decide if AM or PM and update the string
- if(hours > 11 && hours < 17){
- t_str += " PM - Enjoy Your Afternoon!";
- } else if(hours <= 11){
- t_str += " AM - Enjoy Your Morning!";
- }else if(hours >= 17){
- t_str += " PM - Enjoy Your Evening!";
- }
- t.innerHTML = t_str;
- }
- updateTime(); // Called once so time updates as soon as the page loads
- setInterval(updateTime, 1000); // set to update every 1 second after that
- console.log("Clock Loaded!");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement