time
tag. Process it and return time ago string e.g less than minute ago, 5 minutes ago, week, year ago etc.jQuery timeago Plugin Overview
Plugin: | timeago |
Author: | Ryan McGeary |
Category: | Date & Time |
Published: | January 20, 2024 |
File Type: | zip archive (HTML, CSS & JavaScript ) |
Package Size: | 9 KB |
Dependencies: | jQuery 3.0 or Latest version |
How to Convert Timestamp To Time Ago
1. To convert timestamps, we need to getting started with jQuery timeago plugin. So, first of all load the jQuery into your HTML document.
<!-- jQuery --> <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
2. After that, include the timeago’s JavaScript file in your website/app.
<!-- timeago JS --> <script src="js/jquery.timeago.js"></script>
3. Create HTML time
tag with class name "timeago"
and place your timestamp in it.
<time class="timeago" datetime="2019-11-27T09:24:17Z">November 27, 2019</time>
4. Finally, initialize the plugin with time.timeago
selector in jQuery document ready function.
$(document).ready(function(){ $("time.timeago").timeago(); });
For more advance usage, please check the Configurations Options tab.
Advance Configuration Options for jQuery timeago Plugin
The following are some advanced configuration options to convert timestamp to time ago.
Option | Default | Type | Description |
---|---|---|---|
refreshMillis | 60000 | Number |
Milliseconds after update timestamp.
Example: $("time.timeago").timeago({ refreshMillis : 60000, }); |
allowPast | true | Boolean |
Enable / disable past for date.
Example: $("time.timeago").timeago({ allowPast : true, }); |
allowFuture | false | Boolean |
Decide whether to enable timeago for future dates. True for enable.
Example: $("time.timeago").timeago({ allowFuture : false, }); |
localeTitle | false | Boolean |
Decide whether to use locale time for converting date to time ago.
Example: $("time.timeago").timeago({ localeTitle : false, }); |
autoDispose | true | Boolean |
This option enable / disable auto dispose.
Example: $("time.timeago").timeago({ autoDispose : true, }); |
strings | Shown in example | String |
Set of values for time ago string.
Example: $("time.timeago").timeago({ strings : { prefixAgo: null, prefixFromNow: null, suffixAgo: "ago", suffixFromNow: "from now", inPast: 'any moment now', seconds: "less than a minute", minute: "about a minute", minutes: "%d minutes", hour: "about an hour", hours: "about %d hours", day: "a day", days: "%d days", month: "about a month", months: "%d months", year: "about a year", years: "%d years", wordSeparator: " ", numbers: [] } }); |
Changelog
27/11/2019
- Updated v.1.6.7
.
.
.
.
17/7/2008
- Initial release
Similar Code Snippets:
I code and create web elements for amazing people around the world. I like work with new people. New people new Experiences.
I truly enjoy what I’m doing, which makes me more passionate about web development and coding. I am always ready to do challenging tasks whether it is about creating a custom CMS from scratch or customizing an existing system.