Frequently Asked Questions
Frequently Asked Questions
Samples of Countdown Timers > FAQ > Frequently Asked Questions

Search knowledgebase:  

How do I show a leading "0" (zero) in front of single digit numbers?

Solution

To add a zero before single digits, add the following function to the script (either before or after the function "function countdown(yr,m,d,hr,min){…}" but within the <script>...</script> tags):

function leadingZero(i) {
  if (i<10) i="0" + i;
  return i;
}

Then add this:

dhour = leadingZero(dhour);
dmin = leadingZero(dmin);
dsec = leadingZero(dsec);

into the code just before this line:

if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=0){
 
Was this article helpful? yes / no
Article details
Article ID: 2
Category: Customize Timer
Views: 245
Rating (Votes): Article rated 3.7/5.0 (30)

 
« Go back

• • • Powered by Help Desk Software HESK • • •
Licensed to www.rmkwebdesign.com
JavaScript tutorials
Dragon NaturallySpeaking 11 Premium by Nuance