I took this code from PHP with javascript code, live clock and successfully posted it on my website. The code is here:
<?php function d1() { $time1 = time(); $date1 = date("h:i:sa",$time1); echo $date1; } ?> <script> var now = new Date(<?php echo time() * 1000 ?>); function startInterval(){ setInterval('updateTime();', 1000); } startInterval();//start it right away function updateTime(){ var nowMS = now.getTime(); nowMS += 1000; now.setTime(nowMS); var clock = document.getElementById('qwe'); if(clock){ clock.innerHTML = now.toTimeString();//adjust to suit } } </script> <div id="qwe"></div>
However, the time format is displayed as follows:
21:41:44 GMT-0400 (Eastern Standard Time)
I want it to display as
9:41:44 PM
I assume this line
clock.innerHTML = now.toTimeString();
- this is the one I need to change, but I can not find any formats that show it very simply. Do I need to write something myself to show it in this custom format?
source share