Skip to content

Instantly share code, notes, and snippets.

@timrwood
Last active December 14, 2015 15:09
Show Gist options
  • Save timrwood/5105451 to your computer and use it in GitHub Desktop.
Save timrwood/5105451 to your computer and use it in GitHub Desktop.
Moment.js Twitter compliant feed display.
moment.fn.twitter = function () {
var diff = moment().diff(this, 'seconds');
return diff < 60 ? diff + 's' :
diff < 3600 ? ~~(diff / 60) + 'm' :
diff < 86400 ? ~~(diff / 3600) + 'h' : this.format('D MMM');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment