Take the 2-minute tour ×

As the title says I'm facing a problem displaying the right left time to an end date.

I'm using this jquery plugin: http://keith-wood.name/countdown.html

Let's assume that our timestamp is generated by a PHP script like this: $end_date = strtotime($row4['end']); // 2012-05-09 06:00:00 becomes 1336536000

I use this ($i is used inside a loop):

$('.count-<?php echo $i; ?>').countdown({until: new Date(<?php echo $end_date; ?> * 1000), layout: '{dn} days {hnn} hrs {mnn} min {snn} sec', compact: true});

Right now it's 06:21 AM here. Instead of the expected 1 day left result I get "1 days 17 hrs 04 min 21 sec".

What am I missing here?

share|improve this question
what is $i again? –  Baz1nga May 8 '12 at 3:36
$i is a variable that increases through a while loop. $i = 0; while() { $i++; } I'm using this because I want to display the countdown to many items. –  userid53 May 8 '12 at 3:38
I dont want to go into the details of the countdown api, but have you made sure you are working with the same timezone? preferably GMT everywhere. –  Baz1nga May 8 '12 at 3:39
OK now I've set both PHP and jquery countdown timezones to GMT 0 but there's still difference between the PHP countdown and the jquery countdown result. PHP countdown result is that 1 day, 1 hour is left and jquery result is 1 days 20 hrs until 2012-05-09 06:00:00. –  userid53 May 8 '12 at 3:44
add comment

1 Answer

up vote 1 down vote accepted

I have been using the API for quite a while now, but I cann't seem to figure out what's up with your code. Perhaps (but just perhaps) you're using the untill property wrong.

My code that I usually use:

    var countdown = $('#countdown'),
        ts = new Date(<?php echo $date_to * 1000; ?>),
        finished = true;

    if((new Date()) > ts)
        finished = false;

        timestamp   : ts,
        callback    : function(days, hours, minutes, seconds)
            var message = "";

            message += days + " days, ";
            message += hours + " hours, ";
            message += minutes + " minutes, ";
            message += seconds + " seconds ";

            message = (finished ? "Countdown finished" : "left untill the New Year");



Obviously you should extend this to feature singular.

share|improve this answer
Hi, thanks for your reply. Sorry my problem is not with the layout. I think the generated result is wrong. Am I doing wrong the conversion of the UNIX timestamp to a javascript date object? –  userid53 May 8 '12 at 3:33
@ggirtsou Perhaps try multiplying the $end_date in the server side. E.g. - ...Date(<?php echo ($end_date * 1000); ?>)... –  MJA May 8 '12 at 3:41
OK tried that but still get 1 days 20 hrs for end date 2012-05-09 06:00:00 –  userid53 May 8 '12 at 3:45
@ggirtsou Updated my explanation. Please read thought it and test if it works for you. –  MJA May 8 '12 at 3:52
Thank you very much. –  userid53 May 8 '12 at 4:01
add comment

Your Answer


