0

i have a given time difference in seconds from now to the past and want to convert it into years, month, days, hours, minutes considering leap years!

I started to write a very basic function that can not consider the leap years, however i am sure there is a pro way to do it.

Does anyone have good suggestions?

THX

haemse
  • 3,971
  • 5
  • 28
  • 40
  • you mean the std date object? – haemse Apr 01 '12 at 20:34
  • http://stackoverflow.com/questions/6923393/comparing-two-dates-with-javascript-or-datejs-date-difference – mplungjan Apr 01 '12 at 20:58
  • I thought about creating a date obj with the seconds from 1970 and then get the mins hours days ... and subtract 1970 from the years ... however this will not give correct values as the leap years could be in different shift compared to the interval (in sec) from NOW to PAST! – haemse Apr 01 '12 at 21:21

1 Answers1

0

Have you looked at Timeago? The creator says that it is a jQuery plugin but I have ported it to Zepto without problems.

P.S: I wanted to add this as a comment but I am new here and perhaps I don't have enough points to comment? Anyway, check out timeago and let me know if that suits your needs? From your question it sounds to me like it will.

praneetloke
  • 1,953
  • 1
  • 14
  • 15
  • hm ... this is not really an option, as the given format can not further be specifies and after a quick overview it requires an html element ... – haemse Apr 02 '12 at 00:31
  • It doesn't have to be an html element. You can call the timeago function and get the result and do what you want with it. If I am not wrong you can set an option for it to not update any html elements automatically. You could still use this script as a starting point to do what you want with little adjustments to what you need. – praneetloke Apr 02 '12 at 03:57