Fiddle: http://jsfiddle.net/bnsex/1/
I want to use 12 hour clock for this code...
$(document).ready(function() {
setInterval( function() {
var hours = new Date().getHours();
$(".hours, .hour").html(( hours < 10 ? "0" : "" ) + hours);
}, 1000);
});
Your help is much appreciated :D
You can achieve this using the modulus
%
operator, which finds the remainder of a division operation.For example,
11 % 12
and23 % 12
both equal 11, like a 12-hour clock would portray.http://jsfiddle.net/ph7Vf/
Try with this:
Edit: It could be shorter, based on Vulcan's answer: