views:

37

answers:

3

Hi,

let's say im returning a datetime string like this in JS:

"8/18/2010 9:35:27 AM"

I would like to have a function that displays an elapsed time based on the current date-time in this format:

"x days x mins and x secs"

is there a faster way to do this in jQuery? thanks!

+1  A: 

You maybe should return the date/time as epoch / timestamp. Using javascripts

var start = new Date().getTime()

or short

var start = +new Date();

That way you can just substract a new time from that.

var ellapsed = +new Date() - now;

ellapsed now contains that delta, which you can transform into your string.

jAndy
A: 

Use the count-up feature on the jQuery Countdown plugin.

Javid Jamae
i turned to this! thanks man!
Martin Ongtangco
+1  A: 

Do you want something like timeago?

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")

I saw it advertised on stackoverflow..

russau
time ago seems to be a viable solution, but is there a more detailed one?
Martin Ongtangco
i _thought_ it was configurable, but i could be wrong
russau