How to get human friendly date difference in JavaScript

Datetime
By Jad Joubran · 
Last updated Feb 27, 2024
const formatter = new Intl.RelativeTimeFormat("en");

const t1 = 1709042520000;
const t2 = 1709042400000;

// Date diff & convert from ms to minutes
const diff = (t2 - t1) / 60 / 1000;

formatter.format(diff, "minutes");
2 minutes ago