I am getting the following error. I am not able to find out where exactly i went wrong.Can someone help me out with the solution
The code
function() {
this.devices.forEach(device => {
let lastConnect = device.lastConnection.split('+');
lastConnect = lastConnect[0] + 'Z';
let diff = Math.abs(new Date() - new Date(lastConnect));//getting error here
}
I have found out the issue.
This code work only in Javascript
Inorder to make it work in Typescript. Update the code as shown below
No need for Math.abs() to answer this question...
Just using getTime() method converts a Date into a number (Date.prototype.getTime()) so you can make the operation without that error
Check on this example
The simplest answer would be
Another great way:
Math.abs((new Date() as any) - (new Date(lastConnect) as any));