Underscore.date is a javascript date library that helps parse, manipulate, and format dates.
It doesn't modify the native `Date` prototype, so it's safe to drop into any site.
While not dependant on underscore, it does follow the same philosophy, and if underscore exists on your page, underscore.date will mix itself in.
You can download this project in either zip or tar formats.
You can also clone the project with Git by running:
$ git clone git://github.com/timrwood/underscore.date
npm install underscore.date
var _date = require('underscore.date');
console.log(_date('September 9 1999').fromNow());
If underscore exists, underscore.date will mix itself into the underscore namespace, so you can use as you would use an underscore function.
_.date('September 9 1999').fromNow();
Otherwise, you should use _date
.
_date('September 9 1999').fromNow();
Format a Unix timestamp
_date(1300291340510).format("MMMM Do, YYYY") // >>> "March 16th, 2011"
Get timeago for a date string
_date("7-10-1986", "MM-DD-YYYY").fromNow() // >>> "25 years ago"
Get the current time and add 3 hours
_date().add({h:3}).fromNow() // >>> "in 3 hours"
Change the language
_date(1300291340510).format("MMMM Do, YYYY") // >>> "March 16th, 2011"
_date.lang('pt');
_date(1300291340510).format("MMMM Do, YYYY") // >>> "Março 16o, 2011"
_date.lang('en');
_date(1300291340510).format("MMMM Do, YYYY") // >>> "March 16th, 2011"