I have 2 dates that I would like to have the difference of time between them.
if > one year show the number in year only, if > one day show the number of days, if < a day show the number of hours, if < an hour show "You have less than one hour left"
the simplest solution is to use Moment.js:
remainingTime() {
moment.locale('fr_FR');
return moment(new Date(this.finishedAt)).from(new Date(this.startedAt));
}
but does not give the exact result if the remaining time is less than a day.
how can we get the result preferably in native JavaScript or in Moment.js