time-diff-for-humans

get difference between 2 dates in a human readable format, in javascript

Getting Started

run

npm i time-diff-for-humans

import

const timeDiff = require("time-diff-for-humans");
or
import timeDiff from "time-diff-for-humans";

pass into the function a string which is in any valid date format

examples

timeDiff('2022-07-21 12:28:57'); // returns '7 hours ago'
timeDiff("2022-07-21 19:28:57"); // '58 minutes ago'
timeDiff("2022-03-21"); // '4 months ago'
timeDiff("2021-03-21"); // '1 year ago'

you can also pass a locale as a second argument (currently supported locales are only `en` and `ka`)

timeDiff("2022-07-21 19:28:57", "ka"); //returns '1 საათის წინ'

GitHub

View Github