I have 2 dates that I would like to have the difference between them in days and if less than a one day simply show "less than a day".
remainingTime() {
// Scientific notation of 8.64e+7
const DAY_IN_MILLISECONDS = 8.64 * (10 ** 7);
const date1 = new Date('2019-02-28T01:22:06.671Z').getTime();
const date2 = new Date('2019-02-28T04:01:06.671Z').getTime();
const differenceInMS = date2 - date1;
const days = Math.floor(differenceInMS / DAY_IN_MILLISECONDS);
return (days > 1) ? `They have ${days} days` : (days === 1) ? `They have ${days} day` : `you have less than a day left`;
}
Is this way correct if localization is taken into account?
what exactly is the difference between getTime ()
, getMilliseconds ()
and getUTCMilliseconds ()
?
8.64 * 10 ** 7 === 8.64e7
or '8.64E7' also**
has precedence over*
so you don't need the()
around10 ** 7
\$\endgroup\$