Skip to content

hijonathan/moment.twitter

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
February 4, 2014 11:53
December 9, 2013 09:35
January 24, 2015 10:21
February 4, 2014 11:53

Twitter-like Date Formatter Build Status

moment.twitter.js is an extension to moment.js that formats dates like Twitter.

Usage

Works with AMD, CommonJS and browser environments.

// AMD
define(['moment-twitter'], function(moment) { moment().twitter() });
// CommonJS
var moment = require('moment-twitter');
moment().twitter()
<!-- Browser -->
<script type="text/javascript" src="/moment.js"></script>
<script type="text/javascript" src="/moment-twitter.js"></script>
<script type="text/javascript">
    moment().twitter();
</script>

Works on both past and future dates.

Methods

moment().twitterLong()

Web-friendly formatting.

Examples:

Formats time relative to current time.

moment(moment() + (36e5 * 5)).twitterLong()
// 5 hours

Yes, it does smart pluralization.

moment(moment() + 36e5).twitterLong()
// 1 hour

Times greater than 24 hours are converted to dates like Mar 7

moment(moment() + 6048e5).twitterLong()
// Mar 7

moment().twitter()

For use on mobile (alias moment().twitterShort()).

Examples:

Units single characters, and there are no spaces.

moment(moment() + (36e5 * 5)).twitterShort()
// 5h

Times between 24 hours and 6 days are converted to days.

moment(moment() + (864e5 * 6)).twitterShort()
// 6d

Times greater than 6 days are slash-separated.

moment(moment() + 6048e5).twitterShort()
// 3/7/86