Minimalist Relative Datetime Formatting Pluin With jQuery - relativetime.js

File Size: 3.59 KB
Views Total: 780
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Minimalist Relative Datetime Formatting Pluin With jQuery - relativetime.js

A dead simple and lightweight jQuery datetime formatting plugin which calculates passed or pending datetimes and convert them into more human readable strings.

How to use it:

1. Just include the jQuery relativetime.js plugin after loading jQuery library and we're ready to go.

<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="jquery.relativetime.js"></script>

2. Call the relativeTime() function on the wrapping element. This will convert ...

<div class="demo">2016-12-25 00:00:01</div>

3. Into ...

in 10 months

4. Customize the output strings during initialization.

relativeTime({
  future : "in %s",
  past : "%s ago",
  ss : "seconds",
  ii : "%d minutes",
  hh : "%d hours",
  dd : "%d days",
  ww : "%d weeks",
  mm : "%d months",
  yy : "%d years"
})

This awesome jQuery plugin is developed by onanying. For more Advanced Usages, please check the demo page or visit the official website.