Baby Jai
07-31-2003, 05:34 PM
I need a javascript for a countdown to any date that I put in.
|
Click to See Complete Forum and Search --> : Javascript Countdown? Baby Jai 07-31-2003, 05:34 PM I need a javascript for a countdown to any date that I put in. xataku_nakusute 07-31-2003, 07:44 PM <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Time Until Nats</title> <script type="text/javascript"> <!-- Date.ONE_SECOND = 1000; Date.ONE_MINUTE = Date.ONE_SECOND * 60; Date.ONE_HOUR = Date.ONE_MINUTE * 60; Date.ONE_DAY = Date.ONE_HOUR * 24; Date.ONE_WEEK = Date.ONE_DAY * 7; function TimeUntil (d) {this.time = d.getTime ? d.getTime() : Date.parse(d)} TimeUntil.prototype.valueOf = function () {return this.time - new Date ().getTime()} TimeUntil.prototype.toString = function () { var t = Math.abs(this.valueOf()); var d = Math.floor (t / Date.ONE_DAY); var h = Math.floor ((t % Date.ONE_DAY) / Date.ONE_HOUR); var m = Math.floor ((t % Date.ONE_HOUR) / Date.ONE_MINUTE); var s = Math.floor ((t % Date.ONE_MINUTE) / Date.ONE_SECOND); return (this.valueOf () < 0 ? '-' : '') + [d, d == 1 ? 'day' : 'days', [h, m < 10 ? '0' + m : m, s < 10 ? '0' + s : s].join(':')].join(' '); } var time = new TimeUntil ('2 August 2003 10:00 CDT'); document.write('<p><span id="time">',time , '</span> until NATS.</p>'); if (document.getElementById) var int = setInterval ("if (time < 0) {clearInterval(int); alert('The 2003 National Hooverball championship has begun!')} else {document.getElementById('time').replaceChild(document.createTextNode (time), document.getElementById('time').firstChild)}",0.2 * Date.ONE_SECOND); // --> </script> change all items in orange to what you need Baby Jai 07-31-2003, 08:14 PM do you know how I could do it so it its live countdown, and does not stop? Baby Jai 07-31-2003, 08:15 PM also so it says days hours and minutes instead of just in the time seperation norm xataku_nakusute 07-31-2003, 08:17 PM live countdown?!?! it should be already i believe..... yeah, it already is live, and auto-updating... xataku_nakusute 07-31-2003, 08:20 PM as i said previously, i came across it in another thread, and used the code to try to manipulate it to my advantage... however, to be honest with you, im not very good at pretty much all "realtime"(live) javascripts, im only good at the basic "you type something in, and ill respond to that with something" scripts sorry... you can try to search through this forum for the thread if you want Baby Jai 07-31-2003, 08:27 PM well what i mean by "live" is that it is counting down as you stay on the page, go to my site then go to rewards and you will see what I mean Baby Jai 08-01-2003, 01:57 PM Ok i see this is a dead end, well at least I tried Charles 08-01-2003, 02:03 PM As it currently stands that script will continously update until the time is reached and then it will stop. Charles 08-01-2003, 02:09 PM And the time format is easily adjusted. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Time Until Nats</title> <script type="text/javascript"> <!-- Date.ONE_SECOND = 1000; Date.ONE_MINUTE = Date.ONE_SECOND * 60; Date.ONE_HOUR = Date.ONE_MINUTE * 60; Date.ONE_DAY = Date.ONE_HOUR * 24; Date.ONE_WEEK = Date.ONE_DAY * 7; function TimeUntil (d) {this.time = d.getTime ? d.getTime() : Date.parse(d)} TimeUntil.prototype.valueOf = function () {return this.time - new Date ().getTime()} TimeUntil.prototype.toString = function () { var t = Math.abs(this.valueOf()); var d = Math.floor (t / Date.ONE_DAY); var h = Math.floor ((t % Date.ONE_DAY) / Date.ONE_HOUR); var m = Math.floor ((t % Date.ONE_HOUR) / Date.ONE_MINUTE); var s = Math.floor ((t % Date.ONE_MINUTE) / Date.ONE_SECOND); return (this.valueOf () < 0 ? '-' : '') + [d, d == 1 ? 'day,' : 'days,', h, h == 1 ? 'hour,' : 'hours,', m, m == 1 ? 'minute' : 'minutes', 'and', s, s == 1 ? 'second' : 'seconds'].join(' '); } var time = new TimeUntil ('2 August 2003 10:00 CDT'); document.write('<p><span id="time">',time , '</span> until NATS.</p>'); if (document.getElementById) var int = setInterval ("if (time < 0) {clearInterval(int); alert('The 2003 National Hooverball championship has begun!')} else {document.getElementById('time').replaceChild(document.createTextNode (time), document.getElementById('time').firstChild)}",0.2 * Date.ONE_SECOND); // --> </script> Baby Jai 08-01-2003, 02:12 PM Ok what is the CDT after the time? and can i chagne it to EST? And also it look sidentical to the other one Charles 08-01-2003, 02:38 PM 1) That script uses JavaScript's built in date parsing which recognizes several date-time formats. "CDT" simply stands for Central Daylight Time or you can use UTC offsets. If you omit the time zone the parser will assume the same time zone as the user. "EST" works as well but be note that we are currently in Eastern Daylight Time, "EDT". 2) Cut, paste and run that second script and then reply. Baby Jai 08-01-2003, 07:29 PM YOUR THE MAN!!!!!!!!!!!!!!!!!!!!!!!!!!!!! webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |