package
A tool for calculating relative timestamps to now.
npm install agoGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
ago is a simple function for calculating a timestamp some amount of time ago. (or in the future)
var ago = require("ago")
ago(344) // 344 milliseconds ago, e.g. 1376505400233
ago(344, "ms") // same as above, default unit is "ms"
ago(4, "minutes") // four minutes ago
ago(3, "days") // 3 * 24 hours ago
ago(1, "quarter") // one quarter (13 weeks) ago
ago(2, "months") // months are approximate (30.4375 days)
ago(22, "y") // years are approximate as well (365.25 days)
console.log(new Date(ago(35.3086, "y")))
// Mon Apr 24 1978 00:06:49 GMT-0800 (PDT)
// It also exposes a fromNow() function to calculate future times. e.g:
ago.fromNow(1, "year")
// is just sugar for:
ago(-1, "year")
ago(number [,unit])Calculate a millisecond epoch timestamp relative to right now.
ago.fromNow(number [,unit])This is a convenience function for ago(-number, [,unit]) for finding timestamps in the future.
MIT