jhon2015 / jquery-countdown

Automatically exported from code.google.com/p/jquery-countdown
0 stars 0 forks source link

How do i set the plug-in to countdown to a specific date? #18

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I want to countdown to continue to countdown to a date and not reset every time 
I refresh the page. How do I do this?

Original issue reported on code.google.com by jakeleff...@gmail.com on 22 Jun 2011 at 2:22

GoogleCodeExporter commented 9 years ago
Hello, I have made this with PHP. If you want to know how I did it say it.

Original comment by ceteinte...@gmail.com on 28 Jun 2011 at 8:16

GoogleCodeExporter commented 9 years ago
Yes, I would like to know how you've done this with PHP. I'm trying to set a 
past date (start date: Oct 29, 2010) countdown to a future date (end date: Jan. 
01, 2013. Can you post your PHP solution? Thanks!

Original comment by hartwell...@gmail.com on 11 Jul 2011 at 2:04

GoogleCodeExporter commented 9 years ago
I'm curious as well. Would like to set a countdown "EndDate" instead of a 
"StartTime"

Original comment by slick.c...@gmail.com on 14 Jul 2011 at 5:47

GoogleCodeExporter commented 9 years ago
I would also love to know how to do this! I'm pretty stuck with the countdown

Original comment by jamesfr...@gmail.com on 28 Jul 2011 at 9:54

GoogleCodeExporter commented 9 years ago
same here!

Original comment by thomasry...@gmail.com on 31 Jul 2011 at 10:10

GoogleCodeExporter commented 9 years ago
here is the function I wrote to start to a specific date : 

function GetStartTime() {
    var dateNow = new Date();
    var dateNowElapsedTime = dateNow.getTime() / 1000;

    var endDate = new Date(2012,2-1,3,10,30,0);//Date of 03 fev 2012 (notice the "minus one" for the month...)
    var endDateElapsedTime = endDate.getTime() / 1000;

    var timeStampInSec = endDateElapsedTime - dateNowElapsedTime;

    var minutesTmp = timeStampInSec / 60;
    var seconds = Math.floor(timeStampInSec % 60);
    var hoursTmp = minutesTmp / 60;
    var minutes = Math.floor(minutesTmp % 60);
    var days = Math.floor(hoursTmp / 24);
    var hours = Math.floor(hoursTmp % 24);

    return days + ":" + hours + ":" + minutes + ":" + seconds;
}

THen, when you call the CountDown, just replace the startTime value bye a call 
to the function GetStartTime() : 

$('#counter').countdown({
    stepTime: 60,
    format: 'hh:mm:ss',
    startTime: GetStartTime(),
    digitImages: 6,
    digitWidth: 53,
    digitHeight: 77,
    timerEnd: function() { },
    image: "digits.png"
  });

See the demo / source code in attachment.

Hope it'll help ! 

Enjoy !

Original comment by fami...@perrotey.com on 7 Sep 2011 at 11:51

Attachments:

GoogleCodeExporter commented 9 years ago
Yeah, thank you. But after the first Minute, seconds start at 99 - counting 
down from 99 to 1. 
Is this happening to others or is it just me?

André

Original comment by m...@retrocut.de on 12 Sep 2011 at 11:18

GoogleCodeExporter commented 9 years ago
I found that adding zero padding to the values offers a partial solution to the 
99 seconds problem.
For some reason this only works if the end time is less than 100 days away. I 
hope that someone else can figure out how to extend it past 100 days.

function GetStartTime() {
    var dateNow = new Date();
    var dateNowElapsedTime = dateNow.getTime() / 1000;
    var dateDeparture = new Date(2011,10-1,10,00,00,0); //Date of 10 September 2011 at midnight) notice the "minus one" for the month...)
    var dateDepartureElapsedTime = dateDeparture.getTime() / 1000;      
    var timeStampInSec = dateDepartureElapsedTime - dateNowElapsedTime;

    var minutesTmp = timeStampInSec / 60;
    var seconds = zeroPad(Math.floor(timeStampInSec % 60), 2);
    var hoursTmp = minutesTmp / 60;
    var minutes = zeroPad(Math.floor(minutesTmp % 60), 2);
    var days = zeroPad(Math.floor(hoursTmp / 24), 2);
    var hours = zeroPad(Math.floor(hoursTmp % 24), 2);

    return days + ":" + hours + ":" + minutes + ":" + seconds;
    }

function zeroPad(num,count) {
    var numZeropad = num + '';
    while(numZeropad.length < count) {
        numZeropad = "0" + numZeropad;
        }
    return numZeropad;
}

Original comment by NativeP...@gmail.com on 13 Sep 2011 at 1:59

Attachments:

GoogleCodeExporter commented 9 years ago
Hi,

I have a fix for the 99 seconds past 100 days, as the owner of these repo has 
gone quite please see my new repo:

https://github.com/pfarmer/jquery-countdown

I've got a whole bunch of issues I'm going to be fixing over the next fews 
days, and I'm happy to take any patches etc.

Hope this helps,

Peter

Original comment by pfar...@gmail.com on 21 Sep 2011 at 4:46

GoogleCodeExporter commented 9 years ago
Have now added automatic zero padding.

https://github.com/pfarmer/jquery-countdown

Original comment by pfar...@gmail.com on 22 Sep 2011 at 10:09