0

I have 2 time inputs as 7:07:02 and 7:00

How can I find the difference between these two,I prefer to use jquery, Is there any jquery plugins available for this ? ( please let me know if you know other solutions for this )

Thanks a lot

3
  • 1
    What would be the expected result in this case? Commented Dec 8, 2010 at 17:08
  • guys I expect 0:07:02 as output, thanks Commented Dec 8, 2010 at 17:43
  • It is basic math operations, what is hard about multiplying and dividing some numbers by 60? Commented Dec 8, 2010 at 17:51

2 Answers 2

1

I would recommend Date.js

(Date.parse('7:07:02') - Date.parse('7:00')) / 1000; // => 422 seconds
Sign up to request clarification or add additional context in comments.

6 Comments

@matt why to use a any javascript library for this , we can just achieve with javascript right.
@gov it all boils down to his use cases. We can't read his mind, but already in his example he gives 2 different formats for time. Will it ever include a date? AM or PM? Who knows. I would ask you - why write all the JS to properly parse dates and times when someone else has already done the heavy lifting for you? Date functionality in JS is already pretty sparse. DateJS makes working with date and times in JS trivial.
sorry guys, first value : 7:00 second value : 7:07:02 result: 0:07:02 thank you Matt, hope you can fix this too
You want the result to be the string value "0:07:02" or a numerical value representing 7 minutes and 2 seconds?
either string value or numerical value,I just want to show the result on a input box after user types the second value, 7:07:02 .first value comes from database Thanks a again,
|
0

I don't think you want jquery. Just javascript will accomplish this. Change the two times to Dates and then add/subtract them as you like. Finally convert back to the date format that you want to use.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.