Countdown problem. 00 problem.

the following is a countdown, but there is no processing, there is a 00 situation, I thought that I could not find the entry point to solve this problem, so it is like asking for advice on how to deal with this.

example of 00 situation:
for example, when the countdown is 09 to 59, it should be 09 to 58, but it is 09:59:00

.
setTimeFunc = (time) => {
    const aimTime = new Date(("2018-5-24 09:30:00").replace(/-/g, "/")).getTime();
    const currentTime = new Date().getTime();
    // const days = null;
    // const hours = null;
    // const seconds = null;
    const diffTime = aimTime - currentTime;

    const years = new Date(aimTime).getFullYear() - new Date().getFullYear();
    const month = new Date(aimTime).getMonth() - new Date().getMonth();

    if (years === 0) {
      if (month === 0) {
        const days = Math.floor(diffTime / (1000 * 60 * 60 * 24));
        const hours = Math.floor((diffTime - (days * 1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        const minutes = Math.floor((diffTime - (days * 1000 * 60 * 60 * 24) - (hours * 1000 * 60 * 60)) / (1000 * 60));
        const seconds = Math.floor((diffTime - (days * 1000 * 60 * 60 * 24) - (hours * 1000 * 60 * 60) - (minutes * 1000 * 60)) / 1000);
        console.log(hours);
        this.setState({
          days: days > 9 ? days : "0" + days,
          hours: hours > 9 ? hours : "0" + hours,
          minutes: (minutes) > 9 ? minutes : "0" + minutes,
          seconds: seconds> 9 ? seconds : "0" + seconds
        });
      }
    }
Mar.13,2021

do you want 03 02 01 00 as long as 3 2 1 0? Or 03 02 01 0?

Can you describe

more clearly? what does 00 mean?


there should be "00". The next time of "09:59:01" is "09:59:00" instead of "09:58:59". If you want to remove the "00" secretly-1s, then you setState before you judge whether the current is "00" or not, if it is "00", jump directly to the next second.

Menu