How to display 2 digits of remaining time number [jquery countdown]?

How to display 2 digits of amount of time remaining [jquery countdown]?

My code will show

66days7hours6minutes2seconds

      

but I want to display 2 digits for example.

66days07hours06minutes02seconds

      

how to do it?

http://jsfiddle.net/D3E9G/

+3


source to share


2 answers


You can add leading zeros and then use substr

to cut the string to the length you want:

day = ("00" + day).substr(-2);            
hour = ("00" + hour).substr(-2);            
minute = ("00" + minute).substr(-2);            
second = ("00" + second).substr(-2);

      



The parameter -2

means that you want to take 2 characters from the end of the string.

Updated script

+5


source


try it

if (day < 10) day = "0" + day;
if (hour < 10) hour = "0" + hour;
if (minute < 10) minute = "0" + minute;
if (second < 10) second = "0" + second;

      



DEMO

+2


source







All Articles