Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display 2 digits numbers of time left [countdown jquery]?

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/

like image 939
กหดด ยนรยรา Avatar asked Mar 18 '23 20:03

กหดด ยนรยรา


2 Answers

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

like image 143
Rory McCrossan Avatar answered Mar 24 '23 15:03

Rory McCrossan


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

like image 27
Sridhar R Avatar answered Mar 24 '23 15:03

Sridhar R