digital clock with jquery

Just a simple digital jquery clock that updates every second.

Also added the dropshadow animation, not sure why... ;)

code

<p><span class='digital-clock'></span></p>

<style>
	.digital-clock {
		font-size:80px;
	}
</style>

<script>
$(document).ready(function(){
  clockUpdate();
  setInterval(clockUpdate, 1000);    
});

function clockUpdate() {
  var date = new Date();
  function addZero(x) {
    if (x < 10) {
      return x = '0' + x;
    } else {
      return x;
    }
  }

  function twelveHour(x) {
    if (x > 12) {
      return x = x - 12;
    } else if (x == 0) {
      return x = 12;
    } else {
      return x;
    }
  }

  var h = addZero(twelveHour(date.getHours()));
  var m = addZero(date.getMinutes());
  var s = addZero(date.getSeconds());

  $('.digital-clock').text(h + ':' + m + ':' + s)
}	
</script>

Other Items in js
Page Views

This page has been viewed 189 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹

Random Quote
The happiest People don't have the best of everything, they just make the best of everything.
Unknown