Jquery Clock Example - Jquery

How to create simple clock time in jquery?

Snippet Code


  
Rate this page :
  [ 0 votes]

This is a simple code to make a digital clock for your website.Function digitalClock() is used to display On Time. This jquery code is a easy way to show a digital clock on your websites.

<script type='text/javascript'> var d = new Date(); function digitalClock() { d.setTime(d.getTime() + 1000); var hrs = d.getHours(); var mins = d.getMinutes(); var secs = d.getSeconds(); mins = (mins < 10 ? "0" : "") + mins; secs = (secs < 10 ? "0" : "") + secs; var apm = (hrs < 12) ? "am" : "pm"; hrs = (hrs > 12) ? hrs - 12 : hrs; hrs = (hrs == 0) ? 12 : hrs; var ctime = hrs + ":" + mins + ":" + secs + " " + apm; $("#clock").html(ctime); } $(document).ready(function() { digitalClock(); setInterval('digitalClock()', 1000); }); </script> <div id="clock"> </div>

Tags


Ask Questions

Ask Question