Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7698709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:18:20+00:00 2026-05-31T22:18:20+00:00

How do I remove the unused zeros from my website counter, when it says

  • 0

How do I remove the unused zeros from my website counter, when it says 0d 0h 23m 4s… the “0d” & “0h” should be removed… How do I do this?

Below is a copy of my code, it works I just don’t know how to stop the zeros from showing when it’s not needed. example: the timer reads.. 0d 0h 58m 3s… the days and hoursare at Zero and dont need to be shown so how do I remove them? I hope this gives you a clear picture of what the situation here is.

var year=2012    //-->Enter the count down target date YEAR
var month=3      //-->Enter the count down target date MONTH
var day=27       //-->Enter the count down target date DAY
var hour=0      //-->Enter the count down target date HOUR (24 hour clock)
var minute=00    //-->Enter the count down target date MINUTE
var tz=-5        //-->Offset for your timezone in hours from UTC (see http://wwp.greenwichmeantime.com/index.htm to find the timezone offset for your location)

//    -->DO NOT CHANGE THE CODE BELOW! This is just a personal comment dont mind it<--
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d,hr,min){
theyear=yr;themonth=m;theday=d;thehour=hr;theminute=min
    var today=new Date()
    var todayy=today.getYear()
    if (todayy < 1000) {todayy+=1900}
    var todaym=today.getMonth()
    var todayd=today.getDate()
    var todayh=today.getHours()
    var todaymin=today.getMinutes()
    var todaysec=today.getSeconds()
    var todaystring1=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
    var todaystring=Date.parse(todaystring1)+(tz*1000*60*60)
    var futurestring1=(montharray[m-1]+" "+d+", "+yr+" "+hr+":"+min);
    var futurestring=Date.parse(futurestring1)-(today.getTimezoneOffset()*(1000*60));
    var dd=futurestring-todaystring
    var dday=Math.floor(dd/(60*60*1000*24)*1)
    var dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
    var dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
    var dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
    if(dday<=0&&dhour<=0&&dmin<=0&&dsec<=0){
        document.getElementById('count').innerHTML=current;
        return;
    }
    else {
        document.getElementById('count').innerHTML=+dday+ "d "+dhour+"h "+dmin+"m "+dsec+"s";
        setTimeout("countdown(theyear,themonth,theday,thehour,theminute)",1000);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:18:22+00:00Added an answer on May 31, 2026 at 10:18 pm

    change this line:

    document.getElementById('count').innerHTML=+dday+ "d "+dhour+"h "+dmin+"m "+dsec+"s";
    

    to conditionally show the dday, dhour etc. For example:

    document.getElementById('count').innerHTML= ((dday !=0) ? (dday+ "d ") : "") + ((dhour !=0) ? dhour+"h " : "") +dmin+"m "+dsec+"s";
    

    For more clarity, you can build the string in multiple lines, as such:

    var counterStr = "";
    if (dday != 0)
      counterStr += dday+ "d ";
    if (dhour != 0)
      counterStr += dday + "h ";
    counterStr += dmin+"m "+dsec+"s";
    
    document.getElementById('count').innerHTML = counterStr;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can one remove unused git bracnhes from Tortoise-Git? These branches have been removed
How to find and remove unused Delphi runtime packages from a project that uses
I need a way to remove unused images from my filesystem, i.e. images that
I would like to remove all unused CSS selectors from a common CSS file.
i'm using drupal 6 .Is there any way to remove unused css (eg. from
I am trying to figure out a neat way to remove unused factors from
I'm trying to remove unused spans (i.e. those with no attribute) from HTML files,
Is there any objective reason not to remove unused default includes from C# program?
I love the Remove unused usings command in VS2008, however when running it on
I remove item from ArrayList in foreach loop and get follwing exception. Collection was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.