Issue on Updating jQuery setTimeout()

Issue on Updating jQuery setTimeout()

I am trying to make a simple plugin to calculate date and time by this code:

  1. <div id="timer"></div>

  1. $.fn.timeCounter = function(time) {
  2.     
  3.     var target = new Date(time);
  4. var now = new Date();
  5. var timeDiff = target.getTime() - now.getTime();
  6. if (timeDiff <= 0) {
  7.         clearTimeout(timer);
  8.     }
  9. var seconds = Math.floor(timeDiff / 1000);
  10. var minutes = Math.floor(seconds / 60);
  11. var hours = Math.floor(minutes / 60);
  12. var days = Math.floor(hours / 24);
  13. hours %= 24;
  14.     minutes %= 60;
  15.     seconds %= 60;
  16.     
  17.     $("#timer").append( "<p>"+days+"</p>" );
  18.     $("#timer").append( "<p>"+hours+"</p>" );
  19.     $("#timer").append( "<p>"+minutes+"</p>" );
  20.     $("#timer").append( "<p>"+seconds+"</p>" );
  21. var timer = setTimeout(timeCounter,1000);

  22. };

  23. $("#timer").timeCounter("june 16, 2014 00:01:00");
the code is working fine but I am having problem on displaying actual count down on numbers! can you please let me know how to fix this?