The question is how to format a JavaScript Date
as a string stating the time elapsed similar to the way you see times displayed on Stack Overflow.
e.g.<
I write one with js and python, used in two projects, very nice and simple: a simple library (less then 2kb) used to format date with *** time ago statement.
simple, small, easy used, and well tested.
npm install timeago.js
import timeago from 'timeago.js'; // or use script tag
use api format
.
Sample:
var timeagoIns = timeago();
timeagoIns .format('2016-06-12');
Also you can render in real-time.
var timeagoIns = timeago();
timeagoIns.render(document.querySelectorAll('time'));