How to display 2 digits numbers of time left [countdown jquery] ?
My code will show
66days7hours6minutes2seconds
but I want to display 2 digits number e.g.
66days07hours06minutes02seconds
how to do that ?
http://jsfiddle.net/D3E9G/
You can append the leading zeroes, and then use substr
to cut the string to the required length:
day = ("00" + day).substr(-2);
hour = ("00" + hour).substr(-2);
minute = ("00" + minute).substr(-2);
second = ("00" + second).substr(-2);
The -2
parameter means that you want to take the 2 characters from the end of the string.
Updated fiddle
Try this
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With