Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leading zeros on JQuery Countdown Clock plugin

I'm using a JQuery Countdown Clock plugin from here.

Unfortunately I need to have leading 0 where there are single digits. For example 1:1:22 should display as 01:01:22.

Can anyone help with this?

Thanks

like image 908
Martin Avatar asked Jul 09 '09 15:07

Martin


4 Answers

I got this working using the 'Layout' mode.

http://keith-wood.name/countdownRef.html

My code now looks like this...

        $j('#Countdown').countdown({
            until: until,
            layout: '<div class="countdown_section">' +
                 '<div><span class="digits">{dnn}</span><br/>Days</div>' +
                 '<div><span class="digits">{hnn}</span><br/>Hours</div>' +
                 '<div><span class="digits">{mnn}</span><br/>Minutes</div>' +
                 '<div><span class="digits">{snn}</span><br/>Seconds</div></div>',
            serverTime: since,
            onExpiry: function(){
                render_expire();
            }
        });

Cheers!

like image 170
Martin Avatar answered Nov 11 '22 01:11

Martin


There was a padZeroes option added in version 2.0.0: http://keith-wood.name/countdownRef.html#padZeroes

example:

$("#foo").countdown({
    until: new Date(2014, 11-1, 14),
    padZeroes: true
});
like image 41
Bill Keller Avatar answered Nov 11 '22 00:11

Bill Keller


I added an issue to Countdown project to make new "leading zeros" option

like image 1
Mihailoff Avatar answered Nov 11 '22 01:11

Mihailoff


I couldn't get that layout mode trick working, so I used this:

http://www.fundp.ac.be/sciences/chimie/javas/js_format.html

and spliced the code into the _showFull method in the countdown js file.

like image 1
Martin Burke Avatar answered Nov 10 '22 23:11

Martin Burke