Nodejs Utililty Methods Date Ago Format

List of utility methods to do Date Ago Format

Description

The list of methods to do Date Ago Format are organized into topic(s).

Method

ago()
Number.prototype.ago = function() {
  var d = new Date();
  return (d.getTime() - this); 
};
ago()
Number.prototype.ago = function () {
  var i = this.valueOf();
  var t = new Date().getTime();
  return new Date(t - i);
};
ago()
Date.prototype.ago = function() {
  var diff = (((new Date()).getTime() - this.getTime()) / 1000)
  , day_diff = Math.floor(diff / 86400);
  return day_diff == 0 && (
    diff < 60 && "just now" ||
    diff < 120 && "1 minute ago" ||
    diff < 3600 && Math.floor( diff/60 ) + " minutes ago" ||
    diff < 7200 && "1 hour ago" ||
    diff < 86400 && Math.floor( diff/3600 ) + " hours ago") ||
...
ago()
Date.prototype.ago = function () {
  var now = new Date();
  var seconds_ago = (now.getTime() - this.getTime()) / 1000;
  var time = Math.floor(seconds_ago / 86400);
  var s = (time == 1) ? "" : "s";
  if (seconds_ago < 60) {
    return "less than a minute ago";
  } else if (seconds_ago < 3600) {
    time = Math.round(seconds_ago / 60);
...
Ago()
Date.prototype.Ago = function ()
  var msPerMinute = 60 * 1000;
  var msPerHour = msPerMinute * 60;
  var msPerDay = msPerHour * 24;
  var msPerMonth = msPerDay * 30;
  var msPerYear = msPerDay * 365;
  var elapsed = new Date() - this;
  if (elapsed < msPerMinute)
...