Minimal Time Ago Plugin For jQuery - time-ago.js
File Size: | 38.2 KB |
---|---|
Views Total: | 156 |
Last Update: | |
Publish Date: | |
Official Website: | Go to website |
License: | MIT |

Yet another jQuery time-ago plugin for automatically creating timestamps with a nice readable format.
The plugin automatically replaces ISO 8601 date and time-related data with human-readable formats like '4 days ago' or '2 minutes ago'. It strives to be simple as well as lightweight, weighing in at about 1KB compressed.
How to use it:
1. Add your timestamp in ISO 8601 format to the datetime
attribute as follows:
<time datetime="2021-12-24T12:28:00-07:00" title="12/24/2021"> 2021-12-24 </time>
2. Load the jQuery time-ago plugin in the document.
<script src="/path/to/cdn/jquery.slim.min.js"></script> <script src="/path/to/dist/time-ago.js"></script>
3. Initialize the plugin on the time
element. That's it.
$(function(){ $("[datetime]").timeago(); });
4. Localize the plugin as follows.
switch (s.lang && blog) { // if "s.lang" is Indonesian case 'fr': now = '...'; sec = '...'; min = '...'; hour = '...'; day = ''...'; week = '...'; month = '...'; year = '...'; break; // the default "s.lang" is English default: now = 'just now'; sec = 'seconds ago'; min = 'minutes ago'; hour = 'hours ago'; day = 'days ago'; week = 'weeks ago'; month = 'months ago'; year = 'years ago'; }
$(function(){ $("[datetime]").timeago({ lang: 'fr', }); });
5. Determine whether to enable 'xx seconds ago'. Default: true (disable).
$(function(){ $("[datetime]").timeago({ jutstNow: false, }); });
This awesome jQuery plugin is developed by xxrbm. For more Advanced Usages, please check the demo page or visit the official website.