Mi backend me envía el sello de fecha y hora de un documento y quiero calcular la antigüedad de ese documento en el frontend. Estoy usando el momento pero no sé cómo calcular la diferencia entre ellos.
var TodaysDate = new Date(); //Mon May 09 2022 22:52:42 GMT+0530 (India Standard Time) var DateFromServer = Entity; // 2021-05-02T13:18:00.000Zquiero respuesta en años como 3.4 años
Con momento puedes hacerlo así
const TodaysDate = moment('Mon May 09 2022 22:52:42 GMT+0530'); const DateFromServer = moment('2021-05-02T13:18:00.000Z'); const diff = TodaysDate.diff(DateFromServer, 'year', true); console.log(diff.toFixed(2) + " Years");