1timer();
2
3function timer(){
4 var currentTime = new Date()
5var hours = currentTime.getHours()
6var minutes = currentTime.getMinutes()
7var sec = currentTime.getSeconds()
8if (minutes < 10){
9 minutes = "0" + minutes
10}
11if (sec < 10){
12 sec = "0" + sec
13}
14var t_str = hours + ":" + minutes + ":" + sec + " ";
15if(hours > 11){
16 t_str += "PM";
17} else {
18 t_str += "AM";
19}
20 document.getElementById('time_span').innerHTML = t_str;
21 setTimeout(timer,1000);
22}