Posted By

gfazioli on 10/13/08


Tagged

javascript class countDown


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

gfazioli
SpinZ


countDown Class in Javascript


 / Published in: JavaScript
 

URL: http://www.undolog.com/2008/10/13/una-classe-countdown-in-javascript/

A simple countDown class in Javascript:

  1. /**
  2.  * CountDown Class
  3.  *
  4.  * @author Giovambattista Fazioli
  5.  * @web http://www.undolog.com
  6.  *
  7.  * @param dd (string) 'month day, year'
  8.  *
  9.  */
  10. function countDown( dd ) {
  11. // init target time
  12. var target = new Date( dd );
  13. this.targetTime = target.getTime();
  14. /**
  15. * refresh countdown
  16. */
  17. this.refresh = function() {
  18. var today = new Date();
  19. var currentTime = today.getTime();
  20. // time left
  21. this._leftMilliseconds = (this.targetTime - currentTime);
  22. this._leftSeconds = Math.floor( this._leftMilliseconds / 1000 );
  23. this._leftMinutes = Math.floor( this._leftSeconds / 60 );
  24. this._leftHours = Math.floor( this._leftMinutes / 60 );
  25. // no module
  26. this.leftDays = Math.floor( this._leftHours / 24 );
  27. // for print
  28. this.leftMilliseconds = this._leftMilliseconds % 1000;
  29. this.leftSeconds = this._leftSeconds % 60;
  30. this.leftMinutes = this._leftMinutes % 60;
  31. this.leftHours = this._leftHours % 24;
  32. }
  33. this.refresh();
  34. }

Report this snippet  

You need to login to post a comment.