Skip to content

Instantly share code, notes, and snippets.

View arturcarvalho's full-sized avatar

Artur Carvalho arturcarvalho

View GitHub Profile
@pomber
pomber / timeago.js
Created February 14, 2020 17:22
Get a time ago human friendly string from a date (like dates in twitter).
const MINUTE = 60,
HOUR = MINUTE * 60,
DAY = HOUR * 24,
YEAR = DAY * 365;
function getTimeAgo(date) {
const secondsAgo = Math.round((+new Date() - date) / 1000);
if (secondsAgo < MINUTE) {
return secondsAgo + "s";