Show Current Time using HTML and JavaScript

Show current 12hour clock time using JavaScript. So add or paste given code on your website. Let know how to add given code on website.

How to Do

  • Open website’s theme folder then paste JavaScript code on head section.
 <script type="text/javascript">
function displayTime() {
var date = new Date();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
var meridian = "AM";
if (hours > 12) {
hours = hours - 12;
meridian = "PM";
}
if (hours === 0) {
hours = 12;
}
if (minutes < 10) {
minutes = "0" + minutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}
var time = hours + ":" + minutes + ":" + seconds + " " + meridian;
document.getElementById("clock").innerHTML = time;
}
setInterval(displayTime, 1000);
</script>
  • Then paste <div id=”clock”></div> where you want to show clock time.

Hope this code worked perfectly. If you want to show demo, So click-here and paste codes and see demo.

FAQ

Can paste this code on blogger.
Yes! you can use this code on blogger platform.