Any jquery plugin which automatic update time for all the posts of a page -


I have a page in which many posts are shown posted time, I update every 1 minute after that time Want a simple way to give them the same class and after 1 minute you can get all the elements and update the time. No better solution

You can use a simple plugin like this:

  $ Fn.UpdateSince = Function {interval} {var times = this.map (function () {return {e: $ (this), t: parseint ($ (this). Html ())}}}); Var format = function (t) {if (t> 60) {return Math.floor (t / 60) + 'min ago'} else {return t + 'seconds ago'; }} Var update = function () {var now = new date (). GetTime (); $ .eEch (bar, function (i, o) {o.e.html (format (Math ((- now ota) / 1000));}); }; Window.setInterval (updates, intervals); Updates(); This return; }   

This sets a function that runs at intervals and updates the elements you specify. Elements have basically time in the integer format, meaning 1 9 71-01-01 to millisecond:

  & lt; Div class = "timesince" & gt; 1314952218779 & lt; / Div & gt;   

Usage:

  $ ('time period'). UpdateSince (1000); The   

parameter is the update interval in milliseconds. 1000 is one time once, so if you display time in minutes, you will use a large value, for example every 20 seconds or 20 * 1000 .

The part you want to improve is the function format , which turns seconds into a human readable format. Now it's minutes and seconds before, but you probably want it for a few days, hours or minutes.

Demo:

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -