I need a time differnce in my react componenet. I have used MobX for my state management.Some Part of the code:
<Icon name='clock' /> Expiry Date :- {format(books.returnDate, 'eeee do MMMM')}
<Icon name='hourglass start' />Remaining Time:- {timeDiff(books.returnDate)}
In the above code books.returnDate is bind successfully. Now I need the time difference between books.returnDate
and current Date so I called a function timeDiff
const timeDiff = (t2: Date) => {
const t1 = new Date();
console.log(t1.getDay())
var d2 = t2.getDay();
var d1 = t1.getDay();
return (d2 - d1) / (24 * 3600 * 1000);
}
In timeDiff function the values of both dates are:-
but the difference is not calculated. I am getting an error:
[mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: 'Reaction[observer(LibrarianManager)]' TypeError: t2.getDay is not a function
How Can I find this differece in days?