Showing posts with label digital clock. Show all posts
Showing posts with label digital clock. Show all posts

Tuesday 2 September 2014

Clock running scripts in php with jquery

<div class="col-xs-12 col-sm-12 col-lg-12 cal">
      <p id='demo' class="text-center cal-container"></p> 
   </div>
                       </a>
                       <?php
   
   $current_timestamp = time();
  ?>
                       <script type='text/javascript'>
                        flag = true;
            timer = '';
            phpJavascriptClock();
            setInterval(function(){phpJavascriptClock();},1000);
 
            function phpJavascriptClock()
            {
               
                if ( flag ) {
                    timer = <?php echo $current_timestamp;?>*1000;
                }
                var d = new Date(timer);
                months = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 
'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec');
 
                month_array = new Array('January', 'Febuary', 'March', 
'April', 'May', 'June', 'July', 'Augest', 'September', 'October', 
'November', 'December');
 
                currentYear = d.getFullYear();
                month = d.getMonth();
                var currentMonth = months[month];
                var currentMonth1 = month_array[month];
                var currentDate = d.getDate();
                currentDate = currentDate < 10 ? '0'+currentDate : currentDate;
 
                var hours = d.getHours();
                var minutes = d.getMinutes();
                var seconds = d.getSeconds();
 
                var ampm = hours >= 12 ? 'PM' : 'AM';
                hours = hours % 12;
                hours = hours ? hours : 12; // the hour ’0' should be ’12'
                minutes = minutes < 10 ? '0'+minutes : minutes;
                seconds = seconds < 10 ? '0'+seconds : seconds;
                var strTime = hours + ':' + minutes+ ':' + seconds + ' ' + ampm;
                document.getElementById("demo").innerHTML= currentMonth+' 
' + currentDate+' , ' + currentYear + ' ' + strTime ;
                flag = false;
                timer = timer + 1000;
            }
                       </script>