Convert Timestamp to Time ago using jQuery timeago

The “timeago” is a well developed and highly configurable plugin for jQuery to convert timestamp to time ago. It helps you to convert both past and future dates to “time ago” string. It gets the timestamp from HTML 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: November 27, 2019
File Type: zip archive (HTML, CSS & JavaScript )
Package Size: 9 KB
Dependencies: jQuery 3.0 or Latest version
Last Modified:
MIT
84 views

Code Rating

0
0.0 rating
0 out of 5 stars (based on 0 reviews)
Excellent0%
Very good0%
Average0%
Poor0%
Terrible0%

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 to show the time ago string to users.

$(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

There are no reviews yet. Be the first one to write one.

Submit Your Review