Time shows as Nan on iPhone ONLY

I am not sure why my time left show as NaN when I view it on

iPhone

enter image description here

Mobile Simulator in Chrome showed working

enter image description here

Desktop

I’ve also checked it out on Chrome Desktop mode. It’s working as you can see.

enter image description here

I even tried an experiment the same code I use in jsfiddle

https://jsfiddle.net/bheng/7w8cftyL/

It’s working there too!

Does anyone else face this issue too?


Code

<div class="timeLeft"></div>




function timeDiffCalc(dateFuture, dateNow) {
    let diffInMilliSeconds = Math.abs(dateFuture - dateNow) / 1000;

    const days = Math.floor(diffInMilliSeconds / 86400);
    diffInMilliSeconds -= days * 86400;
    console.log('calculated days', days);

    const hours = Math.floor(diffInMilliSeconds / 3600) % 24;
    diffInMilliSeconds -= hours * 3600;
    console.log('calculated hours', hours);

    const minutes = Math.floor(diffInMilliSeconds / 60) % 60;
    diffInMilliSeconds -= minutes * 60;
    console.log('minutes', minutes);

    let difference = '';
    if (days > 0) {
        difference += (days === 1) ? `${days} day, ` : `${days} days, `;
    }

    difference += (hours === 0 || hours === 1) ? `${hours} hour, ` : `${hours} hours, `;

    difference += (minutes === 0 || hours === 1) ? `${minutes} minutes` : `${minutes} minutes`; 

    return difference;
}


var timeLeft = timeDiffCalc(new Date('2021-02-17 20:44:50'), new Date()); 
$('.timeLeft').text(timeLeft + " more..."); 

Live code/result

https://www.bunlongheng.com/norden?code=l!ght

1 thought on “Time shows as Nan on iPhone ONLY”

Leave a Comment