node package manager
Don’t reinvent the wheel. Reuse code within your team. Create a free org »



Format dates real fancy-like in the browser. Good for search engines and humans.

This was originally implemented on the website, then proved useful enough to extract into a standalone module.

Weighs in at 4K, minified and gzipped.


npm install browser-date-formatter --save


Specify date and format data attributes on all HTML elements you want formatted:

<span data-date="Thu Apr 07 2016 17:00:00 GMT-0700 (PDT)" data-format="%Y-%m-%d">
  (any textContent you put here will be replaced with "2016-04-07")

The date data attribute should be a stringified representation of a JavaScript Date object, e.g. String(new Date())

The format data attribute is optional. If omitted, a human-friendly relative date string like "5 minutes ago" is displayed. If specified, the format is expected to be a strftime pattern, such as %Y-%m-%d.

Require and invoke the function in your javascript code:


When the DOM is ready, this module finds all elements with a data-date attribute and converts their text content to the given data-format. The formatter function is executed every 5 seconds to keep relative dates fresh.

Usage without browserify

If you're not using browserify in your project, you can use the hosted version instead:

<script src=""></script>


npm install
npm test




Generated by package-json-to-readme