javascript - Is there a good jQuery plugin or JS code for time durations? -


I basically want to create the following:

int from 67 to 1 minute 7 seconds

Pseudo-code:

  / p>  

/ parent & lt; Span class = "time" & gt; 67 & lt; / Span & gt; // output & lt; Span class = "time" & gt; 1 minute 7 seconds & lt; / Span & gt; // JS $ ('time'). Format_duration (); Borrowing most of the answers to the cave, it should move as a jQuery plugin:

  jQuery.fn.time_from_seconds = function () {return.Each (function () {var t = parseInt ($ (this) .text (), 10); $ (this) data (' Original ', t); var h = math.flur (t / 3600); t% = 3600; var m = monastery. Floor (t / 60); var s = monastery. Floor (t% 60); $ (This ) .text ((h & gt; 0? H + 'hour' + ((h> 1) 's': ''): '') + (m> M + 'min' + ((M> 1)? 'S' ''): '') + s + 'second' + ((s & gt; 1) 's': ''));}); };  

If you have HTML:

  & lt; Span class = 'time' & gt; 67 & lt; / Span & gt; & Lt; Span class = 'time' & gt; 953 & lt; / Span & gt; & Lt; Span class = 'time' & gt; 3869 & lt; / Span & gt;  

And you say it like this:

  $ ('time'). Time_from_seconds ();  

The HTML is on:

  & lt; Span class = "time" & gt; 1 minute 7 seconds & lt; / Span & gt; & Lt; Span class = "time" & gt; 15 mins 53 secs & lt; / Span & gt; & Lt; Span class = "time" & gt; 1 hour 4 mins 29 seconds & lt; / Span & gt;  

Each element also contains 'origin' along with the originally included seconds.

My answer answers directly to your question, but I'm going to take a shot in the dark: If you want to show that the human time happened sometime ago (i.e., "5 minutes ago "), For this it is. I do not think it accepts seconds as formats, though. It should be a date.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -