:clock8: The original jQuery plugin that makes it easy to support automatically updating fuzzy timestamps (e.g. "4 minutes ago").

Overview

timeago: a jQuery plugin

NPM Bower

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") from ISO 8601 formatted dates and times embedded in your HTML (à la microformats).

Usage

First, load jQuery and the plugin:

<script src="jquery.min.js" type="text/javascript"></script>
<script src="jquery.timeago.js" type="text/javascript"></script>

Now, let's attach it to your timestamps on DOM ready - put this in the head section:

<script type="text/javascript">
   jQuery(document).ready(function() {
     $("time.timeago").timeago();
   });
</script>

This will turn all <time> elements with a class of timeago and a datetime attribute formatted according to the ISO 8601 standard:

<time class="timeago" datetime="2011-12-17T09:24:17Z">December 17, 2011</time>

into something like this:

<time class="timeago" datetime="2011-12-17T09:24:17Z" title="December 17, 2011">about 1 day ago</time>

<abbr> elements (or any other HTML elements) are also supported (this is for legacy microformat support and was originally supported by the library before the time element was introduced to HTML5):

<abbr class="timeago" title="2011-12-17T09:24:17Z">December 17, 2011</abbr>

As time passes, the timestamps will automatically update.

If you want to update a timestamp programatically later, call the update function with a new ISO8601 timestamp of Date object. For example:

$("time#some_id").timeago("update", "2013-12-17T09:24:17Z");
// or
$("time#some_id").timeago("update", new Date());

For more usage and examples: http://timeago.yarp.com/

For different language configurations: visit the locales directory.

Settings

cutoff : Return the original date if time distance is older than cutoff (miliseconds).

// Display original dates older than 24 hours
jQuery.timeago.settings.cutoff = 1000*60*60*24;

Changes

Version Notes
1.6.x (compare) Wraped locales in UMD wrappers; locale improvements
1.5.x (compare) Added Date as argument to update function; locales
1.4.x (compare) Added allowPast setting; locale updates
1.3.x (compare) Added updateFromDOM function; bug fixes; bower support
1.2.x (compare) Added cutoff setting; locale updates
1.1.x (compare) Added update function; locale updates
1.0.x (compare) locale updates; bug fixes; AMD wrapper
0.11.x (compare) natural rounding; locale updates;
0.10.x (compare) locale updates
0.9.x (compare) microsecond support; bug fixes
0.8.x (compare) <time> element support; bug fixes
0.7.x (compare) locale function overrides; unit tests
... ...

Author

Ryan McGeary (@rmm5t)

License

MIT License

Comments
  • Create bower.json

    Create bower.json

    I've created this bower.json manifest to register the library in bower. The version is changed to 1.4.0 because I guest this, and previous commits, can generate a new release. The folders test and vendors are not required in production, so they are ignored and jquery is added as a dependency (due it's a jquery plugin) but I'm not sure about the minimal jquery version required.

    opened by oscarotero 13
  • Plugin only works with TIME elements; should only require @datetime=ISO8601

    Plugin only works with TIME elements; should only require @datetime=ISO8601

    Project website docs imply that the plugin will work as long as a datetime attribute is present with an ISO 8601 date, but in Chrome 51.0.2679.0 (Official Build) dev (64-bit), the plugin fails to replace the text UNLESS a <time> element is used. <span> doesn't work, for example. (Oddly, the plugin does set the @title attr, it just doesn't replace the value.) I spent a bunch of time trying to "debug" my code because I misunderstood the plugin's strong preference for <time> and <abbr> elements.

    repro: http://codepen.io/jm3/pen/ZWLOoj

    opened by jm3 10
  • Removing public symlink to its own directory

    Removing public symlink to its own directory

    Having a symlink that points to its own directory is a problem for some scripts that recurse through every folder.

    I had a specific problem where this caused Django's collectstatic management command to run into an infinite loop.

    opened by philfreo 10
  • Allow to specify what is current time

    Allow to specify what is current time

    Currently it is hardcoded as browser current time, but it would be usefull to allow user specify that is current time (something like this http://gist.github.com/398904).

    In my case it necessary because I have to display intervals like '2 seconds' ago and very often browser time is different from server time in couple of seconds. With this patch I can specify current time as server time and display correct intervals.

    1 - Ready 
    opened by valodzka 10
  • jQuery.timeago is undefined jQuery 3.4.0

    jQuery.timeago is undefined jQuery 3.4.0

    I'm using yarn, and yesterday I needed to add a new package. This was my package.json:

      "dependencies": {
        "bootstrap": "4.3.1",
        "jquery": "^3.2.1",
        "jqvmap": "^1.5.1",
        "odometer": "^0.4.8",
        "popper.js": "^1.14.7",
        "select2": "^4.0.6-rc.1",
        "simplelightbox": "^1.12.1",
        "timeago": "^1.6.5"
      }
    

    This installed a new version of jQuery, the 3.4.0 version. It seems this version is incompatible with timeago.js since jQuery.timeago is undefined in developper tools.

    I updated my dependencies with "jquery": "^3.2.1 <3.4.0", and it works again.

    opened by lowwa132 9
  • option to have tooltip change only

    option to have tooltip change only

    based on https://github.com/rmm5t/jquery-timeago/wiki/Tips#switch-between-time-ago-and-back made dates clickable, my user's aren't still happy.

    so i tried to make that by default it's not turned on, so that click activates it:

        // jquery timeago
        var $timeago = $('abbr.timeago');
        // on click toggle between views
        var timeago_toggle = function () {
            var $el = $(this);
            var old = $el.attr('title');
            $el.attr('title', $el.text());
            $el.text(old);
        };
    
            // enable only on click
            $timeago.click(function () {
                $(this)
                    .timeago()
                    .unbind('click')
                    .click(timeago_toggle);
            })
    

    https://github.com/eventum/eventum/commit/91e4f66477c35c5c7c86cded76f5b9aca480057a

    it works well, but tooltip now is supposed to show relative date, but instead it's iso6861 timestamp stright from html, which is rather ugly. so, do you have suggestion here or maybe add some kind of support for this?

    image

    opened by glensc 9
  • Timeago abr tooltip showing the date in UTC instead of locale timezone

    Timeago abr tooltip showing the date in UTC instead of locale timezone

    I'm using the following ASP.NET MVC custom HtmlHelper I got from stackoverflow:

    public static MvcHtmlString Timeago(this HtmlHelper helper, DateTime dateTime)
    {
         var tag = new TagBuilder("abbr");
         tag.AddCssClass("timeago");
         tag.Attributes.Add("title", dateTime.ToString("s") + "Z");
         tag.SetInnerText(dateTime.ToString());
    
         return MvcHtmlString.Create(tag.ToString());
     }
    

    I'm passing a datetime converted to UTC using dateTime.ToUniversalTime(). The helper is generating the following abbr tag:

    <abbr title="2014-03-14T01:41:25Z" class="timeago">14/03/2014 01:41:25 a.m.</abbr>
    

    The innex text is properly replaced by the "x ago", but the tooltip shows the full date in UTC instead of the client browser timezone.

    What am I missing?

    opened by empz 9
  • Add support for UTC dates

    Add support for UTC dates

    This pull request adds a new setting 'useUTC'. When set to true, the plugin uses current UTC datetime instead of local datetime. Very useful when the server provided timestamp is in UTC.

    opened by rroyter 8
  • Add spm support

    Add spm support

    A nicer package manager: http://spmjs.io Documentation: http://spmjs.io/documentation

    http://spmjs.io/package/jquery-timeago


    It is a package manager based on Sea.js which is a popular module loader in China.

    spmjs focus in browser side. We supply a complete lifecycle managment of package by using spm.

    If you need ownership of jquery-timeago in spmjs, I can add it for your account after signing in http://spmjs.io.

    opened by sorrycc 8
  • Possibility to add the timestamp to the timeago string

    Possibility to add the timestamp to the timeago string

    Hi,

    I needed the possibility to add the timestamp to the timeago string to have something like "Yesterday 10:28" so I added the distanceMillis to the substitute function. Here is my diff. Maybe you could integrate it or give me the right to commit.

    @@ -62,23 +62,23 @@
           var days = hours / 24;
           var years = days / 365;
    
    -      function substitute(stringOrFunction, number) {
    -        var string = $.isFunction(stringOrFunction) ? stringOrFunction(number) : stringOrFunction;
    +      function substitute(stringOrFunction, value, millis) {
    +        var string = $.isFunction(stringOrFunction) ? stringOrFunction(value, millis) : stringOrFunction;
             var value = ($l.numbers && $l.numbers[number]) || number;
             return string.replace(/%d/i, value);
           }
    
    -      var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
    -        seconds < 90 && substitute($l.minute, 1) ||
    -        minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
    -        minutes < 90 && substitute($l.hour, 1) ||
    -        hours < 24 && substitute($l.hours, Math.round(hours)) ||
    -        hours < 48 && substitute($l.day, 1) ||
    -        days < 30 && substitute($l.days, Math.floor(days)) ||
    -        days < 60 && substitute($l.month, 1) ||
    -        days < 365 && substitute($l.months, Math.floor(days / 30)) ||
    -        years < 2 && substitute($l.year, 1) ||
    -        substitute($l.years, Math.floor(years));
    +      var words = seconds < 45 && substitute($l.seconds, Math.round(seconds), distanceMillis) ||
    +        seconds < 90 && substitute($l.minute, 1, distanceMillis) ||
    +        minutes < 45 && substitute($l.minutes, Math.round(minutes), distanceMillis) ||
    +        minutes < 90 && substitute($l.hour, 1, distanceMillis) ||
    +        hours < 24 && substitute($l.hours, Math.round(hours), distanceMillis) ||
    +        hours < 48 && substitute($l.day, 1, distanceMillis) ||
    +        days < 30 && substitute($l.days, Math.floor(days), distanceMillis) ||
    +        days < 60 && substitute($l.month, 1, distanceMillis) ||
    +        days < 365 && substitute($l.months, Math.floor(days / 30), distanceMillis) ||
    +        years < 2 && substitute($l.year, 1, distanceMillis) ||
    +        substitute($l.years, Math.floor(years), distanceMillis);
    
           return $.trim([prefix, words, suffix].join(" "));
         },
    

    After that I could add strings in this way:

    day: function(value, millis) { return writeYesterday(millis, "gestern, %s Uhr"); },
    

    the function looks like:

    function writeYesterday(ms, str) {
            var writeDate = new Date(new Date().getTime() - ms);
    
            var returnStr = str.replace(/%s/i, fillDate(writeDate.getHours()) + ':' +
                                               fillDate(writeDate.getMinutes()));
            return returnStr;
        }
    
    opened by dirkaholic 8
  • [Authorize] About the website (timeago.org) code

    [Authorize] About the website (timeago.org) code

    I open a project which is detached from my work.

    The website is here. code saved from http://timeago.yarp.com/, and I add the code source here.

    The website caused controversy, so open the issue for authorize, if not, I will remove it.

    opened by hustcc 7
  • How can I add translation for months' names?

    How can I add translation for months' names?

    Hello.

    I'd like to type the date in 'title' in english i.e.: title="July 17, 2008" and I'd like to add the translation for the name of the 12 months in a script, i.e. July: "Julho", as we have in locale files, so when I set up the locale to portuguese the user would get the date not as July 17, 2008 but Julho 17, 2008. Is there a way to do it?

    Example

    Translating months' names

    Best regards.

    opened by jarisgv 6
  • NaN variable appear after pasing variable to timeago

    NaN variable appear after pasing variable to timeago

    thats how i have done it:

    jQuery.timeago(elm.spCreatedAt.toString())

    and this is the value of elm.spCreatedAt:

    spCreatedAt: date: "2020-10-01 13:38:15.000000" timezone: "Europe/Berlin" timezone_type: 3

    opened by PaYo90 0
  • JQuery Deprecated Methods

    JQuery Deprecated Methods

    JQuery has deprecated trim and isFunction methods.

    Replace $.trim() with value.trim()..

    $.trim(element.text()) becomes element.text().trim()

    Replace $.isFunction(stringOrFunction) with typeof stringOrFunction === "function"

    opened by melloware 1
  • Add setting to pass options for date.toLocaleString()

    Add setting to pass options for date.toLocaleString()

    I personally don't like the format that toLocaleString() returns (24/10/2019 2:36:56).

    It would be nice if there was an option to pass its options like dateStyle: 'long', timeStyle: 'short', etc.

    e.g.

    $.timeago.settings.LocaleFormat = {dateStyle: 'medium', timeStyle: 'short', hour12: true};
    // $(this).attr("title", date.toLocaleString(undefined, $t.settings.LocaleFormat));
    

    will show as Oct 8, 2019, 2:36 AM

    opened by ghost 0
Releases(v1.6.7)
  • v1.6.7(Apr 23, 2019)

  • v1.6.6(Apr 12, 2019)

  • v1.6.5(Feb 24, 2019)

  • v1.6.4(Feb 24, 2019)

  • v1.6.3(Feb 23, 2018)

  • v1.6.1(Jul 17, 2017)

  • v1.6.0(Jul 17, 2017)

  • v1.5.4(Jan 19, 2017)

    Changes:

    • Prevent multiple multiple concurrent setInterval for the same instance #313

    Cleanup:

    • Convert all files to UNIX line endings #287
    • Add missing semicolons #288
    • Add missing curly braces for an if #289
    • Use jQuery more efficiently in the test script #291
    • Add a "monospace" fallback for pre/tt in the CSS #292
    • Switch to jQuery 2.2.4 #293
    • Update to the asynchronous-loading Google Analytics code #294
    • Always use strict comparisons #295
    • Drop the CDATA from the script tags #297

    Locale Updates:

    • Estonian: Remove unnecessary if condition #290
    • Add Persian Numbers #303
    • Add Persian Numbers #304
    • Improve Catalan localization #306
    • Fix Russian locale #309
    Source code(tar.gz)
    Source code(zip)
  • v1.5.3(Jun 20, 2016)

    Features:

    • Documentation (#271, Thanks @RomainSauvaire)
    • Revert back to original value after cutoff expires (#284, Thanks @julmis)

    Locale Updates:

    • Slovenian locale fixes (#272, Thanks @drye)
    • New abbreviated German locale (#274, Thanks @Pappmann)
    • New abbreviated Turkish locale (#282, Thanks @pikshub)
    • New Azerbaijani locales (#285, Thanks @Jamil-Najafov)
    Source code(tar.gz)
    Source code(zip)
  • v1.5.2(Feb 12, 2016)

  • v1.5.1(Feb 3, 2016)

  • v1.5.0(Jan 21, 2016)

Owner
Ryan McGeary
Business Starter, Software Consultant, Rubyist, CrossFit Nerd, Amateur Triathlete, Father, @McGearyGroup Owner, @BusyConf Founder. ChargeStack Founder.
Ryan McGeary
Countdown - jQuery CountDown Clock - Simple countdown plugin for product special offers

TronLink Wallet Address TRX - BTC - BTT - USDT: TH9RyofE7WiDDVVFLMJgFns2ByBRmgQzNB jQuery Countdown Clock jQuery countdown plugin that accounts for ti

E-Piksel 33 Aug 30, 2022
Nepali Date Picker jQuery Plugin 🇳🇵

Nepali Date Picker Nepali Date Picker jQuery Plugin for everyone. ???? Installation npm install nepali-date-picker Demo and Documentation https://leap

Leapfrog Technology 70 Sep 29, 2022
jQuery plugin to allow dragging and dropping of elements and sorting of lists and other nested structures.

Drag and Drop Basic jQuery plugin to allow drag and drop: dragging dropping of dragged elements sorting of lists and other nested html structures (ul,

Ole Trenner 12 Aug 26, 2021
Timezone support for moment.js

Moment Timezone IANA Time zone support for Moment.js Project Status Moment-Timezone is an add-on for Moment.js. Both are considered legacy projects, n

Moment.js 3.7k Jan 1, 2023
Replace moment with dayjs, support use in vite, rollup, webpack

Replace moment with dayjs, support use in vite, rollup, webpack

null 11 Dec 6, 2022
Easy to get a date.

date2data 테이블에 날짜별 데이터 넣을 때마다 새로 객체 만들어서 작업하기가 매우 귀찮아서 만들었다. moment.js를 쓰기에는 구현하고자 하는 내용이 너무 가벼웠음 Install npm i date2data Usage import {getMonthlyDate

Duho Kim 3 Apr 12, 2022
This library provide a fast and easy way to work with date.

Calendar.js Calendar.js provide a fast way to work with dates when you don't wanna deal with hours, minute, second and so on. It means that Calendar.j

ActuallyNotaDev 3 Apr 27, 2022
jQuery Timer: Start/Stop/Resume/Remove pretty timer inside any HTML element.

jQuery Timer plugin Lightweight, well tested jQuery pretty timer plugin Start, Pause, Resume and Remove a timer inside any HTML element. Get notified

Walmik Deshpande 291 Nov 4, 2022
⚡️The Fullstack React Framework — built on Next.js

The Fullstack React Framework "Zero-API" Data Layer — Built on Next.js — Inspired by Ruby on Rails Read the Documentation “Zero-API” data layer lets y

⚡️Blitz 12.5k Jan 4, 2023
jQuery plugin for fuzzy search in autocomplete

fuzzycomplete jQuery plugin for fuzzy search in an autocomplete form, which uses Fuse.js. By harnessing the flexibility Fuse.js, this plugin allows yo

null 14 Nov 1, 2021
:clock8: :hourglass: timeago.js is a tiny(2.0 kb) library used to format date with `*** time ago` statement.

timeago.js timeago.js is a nano library(less than 2 kb) used to format datetime with *** time ago statement. eg: '3 hours ago'. i18n supported. Time a

hustcc 4.9k Jan 4, 2023
A tiny, efficient, fuzzy search that doesn't suck

▒ μFuzzy A tiny, efficient, fuzzy search that doesn't suck Introduction This is my fuzzy ?? . There are many like it, but this one is mine. uFuzzy is

Leon Sorokin 1.9k Dec 25, 2022
Smart Time Ago is a little jQuery library to update the relative timestamps in your document.

Smart Time Ago Smart Time Ago is a little jQuery library to update the relative timestamps in your document intelligently. (e.g "3 hours ago"). It's o

Pragmatic.ly 588 Dec 6, 2022
This plugin can generate timestamps for video, audio and Bilibili video, it takes you to the corresponding video/audio position when clicked.

logseq-plugin-media-ts 本插件能够生成视频、音频以及 B 站视频的时间戳,点击时间戳后会跳转到对应的音视频位置。 This plugin can generate timestamps for video, audio and Bilibili video, it takes

Seth Yuan 58 Jan 3, 2023
This plugin allows side-by-side notetaking with videos. Annotate your notes with timestamps to directly control the video and remember where each note comes from.

Obsidian Timestamp Notes Use Case Hello Obsidian users! Like all of you, I love using Obsidian for taking notes. My usual workflow is a video in my br

null 74 Jan 2, 2023
Easy and automatic updating way

Changes: ENTER Intents for client! const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBE

Akif Yüce 4 Jul 16, 2022
An easy to implement marquee JQuery plugin with pause on hover support. I know its easy because even I can use it.

Simple-Marquee Copyright (C) 2016 Fabian Valle An easy to implement marquee plugin. I know its easy because even I can use it. Forked from: https://gi

null 16 Aug 29, 2022
"Jira Search Helper" is a project to search more detail view and support highlight than original jira search

Jira Search Helper What is Jira Search Helper? "Jira Search Helper" is a project to search more detail view and support highlight than original jira s

null 41 Dec 23, 2022
jBox is a jQuery plugin that makes it easy to create customizable tooltips, modal windows, image galleries and more.

jBox jBox is a jQuery plugin that makes it easy to create customizable tooltips, modal windows, image galleries and more. Demo: https://stephanwagner.

Stephan Wagner 1.4k Dec 15, 2022
a jQuery plugin that makes it easy to internationalize your web site.

jquery.localize.js A jQuery plugin that makes it easy to i18n your static web site. Synopsis Lazily loads JSON translation files based on a simple nam

Jim Garvin 469 Dec 17, 2022