Skip to content

zarkoselak/pretty-date-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pretty-date-js ⌛ npm version

Usage

To use pretty-date-js first install it from npm npm install pretty-date-js

after module is installed require it in your project
var pretty = require('pretty-date-js');

then just pass date in valid time format
var myPrettyDate = pretty("2012-03-25", options);

{ 
	value: 4, 
	lang: "years" 
}

Date

For date input use valid date format or timestamp e.g.

Full format date
pretty("Wed Mar 25 2015 01:00:00 GMT+0100 (W. Europe Standard Time)",options);

"1 year ago"

ISO 8601
pretty("2015-03-25", options);

"1 year ago"

Long Dates
pretty("JANUARY, 25, 2015", options);

"1 year ago"

Short Dates
pretty("03/25/2016", options);

"2 months ago"

If you are not familiar with date formats please read more here

Options

Use options to override default ENG language settings in module

This is default options object

{
	lang: {
		seconds: ["second", "seconds"],
		minutes: ["minute", "minutes"],
		hours: ["hour", "hours"],
		days: ["day", "days"],
		months: ["month", "months"],
		years: ["year", "years"],
		misc: ["ago", "Invalid input, please check formating"]
	}
}

You can override it with your language to get output like this:

EN 1 hour ago
FR Il y a 1 heure

Example

Enter example folder and run npm install to install webpack and webpack-dev-server

For development server run npm run start and open
http://localhost:8080/webpack-dev-server/
in your browser or just run npm run build for builing example bundle.

To change time in example just update data variable
var date = "2016-06-05T16:00:00";

Example

Demo

Please try live demo

License

MIT

About

⌛ javascript module for pretty/relative date with basic localization

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published