https://github.com/netcode/node-prettydate
format old JavaScript dates in a “pretty” way. ex : 2 hours ago , 3 minutes ago
https://github.com/netcode/node-prettydate
Last synced: about 1 year ago
JSON representation
format old JavaScript dates in a “pretty” way. ex : 2 hours ago , 3 minutes ago
- Host: GitHub
- URL: https://github.com/netcode/node-prettydate
- Owner: netcode
- License: mit
- Created: 2013-08-23T14:38:30.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2019-11-07T14:29:23.000Z (over 6 years ago)
- Last Synced: 2025-04-11T22:46:41.258Z (about 1 year ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 13
- Watchers: 4
- Forks: 8
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
node-prettydate
===============
format old JavaScript dates in a “pretty” way. ex : 2 hours ago , 3 minutes ago
inspired by the John Resig Pretty Date plugin for jQuery (http://ejohn.org/blog/javascript-pretty-date/)
## Usage
`npm install pretty-date`
```javascript
var prettydate = require("pretty-date");
console.log(prettydate.format(new Date("Fri Aug 23 2013 17:30:34 GMT+0200 (EET)")));
```
## Examples
```javascript
var prettydate = require("pretty-date");
console.log( prettydate.format( new Date( new Date() - -2*365*24*60*60*1000 )));
console.log( prettydate.format( new Date( new Date() - -365*24*60*60*1000 )));
console.log( prettydate.format( new Date( new Date() - -2*30*24*60*60*1000 )));
console.log( prettydate.format( new Date( new Date() - -30*24*60*60*1000 )));
console.log( prettydate.format( new Date( new Date() - -2*24*60*60*1000 )));
console.log( prettydate.format( new Date( new Date() - -24*60*60*1000 )));
console.log( prettydate.format( new Date( new Date() - -2*60*60*1000 )));
console.log( prettydate.format( new Date( new Date() - -60*60*1000 )));
console.log( prettydate.format( new Date( new Date() - -2*60*1000 )));
console.log( prettydate.format( new Date( new Date() - -60*1000 )));
console.log( prettydate.format( new Date( new Date() - -2*1000 )));
console.log( prettydate.format( new Date( new Date() - -1*1000 )));
console.log( prettydate.format( new Date()));
console.log( prettydate.format( new Date( new Date() - 1*1000 )));
console.log( prettydate.format( new Date( new Date() - 2*1000 )));
console.log( prettydate.format( new Date( new Date() - 60*1000 )));
console.log( prettydate.format( new Date( new Date() - 2*60*1000 )));
console.log( prettydate.format( new Date( new Date() - 60*60*1000 )));
console.log( prettydate.format( new Date( new Date() - 2*60*60*1000 )));
console.log( prettydate.format( new Date( new Date() - 24*60*60*1000 )));
console.log( prettydate.format( new Date( new Date() - 2*24*60*60*1000 )));
console.log( prettydate.format( new Date( new Date() - 30*24*60*60*1000 )));
console.log( prettydate.format( new Date( new Date() - 2*30*24*60*60*1000 )));
console.log( prettydate.format( new Date( new Date() - 365*24*60*60*1000 )));
console.log( prettydate.format( new Date( new Date() - 2*365*24*60*60*1000 )));
/* outputs
* 2 years from now
* 1 year from now
* 2 months from now
* 1 month from now
* 2 days from now
* tomorrow
* 2 hours from now
* 1 hour from now
* 2 minutes from now
* 1 minute from now
* 2 seconds from now
* 1 second from now
* just now
* 1 second ago
* 2 seconds ago
* 1 minute ago
* 2 minutes ago
* 1 hour ago
* 2 hours ago
* yesterday
* 2 days ago
* 1 month ago
* 2 months ago
* 1 year ago
* 2 years ago
*/
```
## Contributions
feel free to fork and add features , fix bugs and your pull request is more than welcome