"Timeago" a jQuery plugin

"Timeago" a jQuery plugin

Timeago a jQuery plugin

What?

Timeago is a jQuery plugin that makes it easy to support automatically updating fuzzy timestamps (e.g. "4 minutes ago" or "about 1 day ago"). Download, view the examples, and enjoy.

You opened this page . (This will update every minute. Wait for it.)

This page was last modified .

Ryan was born .

Why?

Timeago was originally built for use with Yarp.com to timestamp comments.

  • Avoid timestamps dated "1 minute ago" even though the page was opened 10 minutes ago;timeago refreshes automatically.
  • You can take full advantage of page caching in your web applications, because the timestamps aren't calculated on the server.
  • You get to use standard HTML5 tags.

How?

First, load jQuery and the plugin:

Now, let's attach it to your timestamps on DOM ready:

This will turn all elements with a class of and an ISO 8601 timestamp in the datetime:

timeago 2008-07-17T09:24:17Z

into something like this:

2008-07-17T09:24:17Z

which yields: . As time passes, the timestamps will automatically update.

You can also use it programmatically:

less than a minute ago 7 years ago 7 years ago

To support timestamps in the future, use the setting:

To disable timestamps in the past, use the setting. This setting is set to true by default. When set to false, if the time is in the past then instead of displaying a message like "5 minutes ago" a static message will be displayed. The staic message displayed can be configured with the setting:

Excusez-moi?

Yes, timeago has locale/i18n/language support. Here are some configuration examples. Please submit a GitHub pull request for corrections or additional languages.

Where?

Download the "stable" release.

The code is hosted on GitHub: http://github.com/rmm5t/jquery-timeago. Go on, live on the edge.

Who?

Timeago was built by Ryan McGeary (@rmm5t) while standing on the shoulders of giants. John Resig wrote about a similar approach. The verbiage was based on the ActionView helper in Ruby on Rails.

When?

Timeago was conceived . (Yup, that's powered by timeago too)

What else?

The HTML5 tag is strongly recommended, but the legacy datetime microformat using the tag is also supported:

timeago 2008-07-17T09:24:17Z

Attach timeago like so:

Are you concerned about time zone support? Don't be. Timeago handles this too. As long as your timestamps are in ISO 8601 format and include a full time zone designator (±hhmm), everything should work out of the box regardless of the time zone that your visitors live in.

Very interesting plugin. Just keep in mind that Linkedin strips out all HTML in your post, so the examples don't work. Linkedin isn't the best place to post technical articles, not yet.

To view or add a comment, sign in

More articles by Mohammed Qasem

Others also viewed

Explore content categories