Reputation: 784
I am trying to use this jQuery countdown - http://code.google.com/p/jquery-countdown/. Because it have a nice animations, but seems like it isn't completed yet, because it has not well documented.
So I have to modified it to use countdown like setting a date and time to event. Something like - var date = 'January 28, 2012 12:35:10';
and it will count down to this time, but it now works different. Like you can see in this example , as you can see this example is set to 1 day 12h 12min 00s but it every time restarts when you refresh the page.
So can somebody tell how to modify this plugin to work like I wanna it?
Here is one more example, as you can see there is countdown to next fight, and it seams like they are using same plugin.
Or there is alternative to this plugin (also with animations) ?
Upvotes: 1
Views: 1303
Reputation: 316
$date1 = new DateTime('2013-02-18');
echo $date1->format('d H:i:s')."
";
$date2 = new DateTime("now");
echo $date2->format('d H:i:s')."
";
$diff = date_diff($date1, $date2); echo $diff->format('%d %H:%i:%s');
Upvotes: 0
Reputation: 260
See if you can find what you need from jCounter, it has real timezone support and accepts custom values to run timers, though it does not have that fancy animation. I hope it helps.
Upvotes: 0
Reputation: 71
If that jquery plugin requires a duration, you'll have to calculate that for it. You already know the end time: endDate = new Date('January 28, 2012 12:35:10');
and you know the current time: curDate = new Date();
so compute the difference: duration = endDate.getTime() - curDate.getTime(); // this is the milliseconds between the two dates
Now use those milliseconds to figure out how many hours, minutes, seconds, etc. you need to set up the plugin.
Upvotes: 0
Reputation: 18546
That plug in doesn't support setting a datetime to count down to. You can only give it 'dd:hh:mm:ss' that the timer should have left. Its like plugging in a date/time into a microwave and expecting it to work.
You'll need to take your future date and subtract now from it, then figure out how many days, hours, minutes, and seconds there are left. Once you have that, that's the value you want to use.
Upvotes: 1