I have two time picker jquery controls that have time in the format of “10 AM”, “11 AM”, “12 PM” etc.. How do I get the difference between these two time selections.
For example, if I pick 10 AM in first control, 1 PM in second control, I need to the difference in hours which is 3. How can I do this in javascript.
var FirstTime = container.find('#1time').val();
var SecondTime = container.find('#2time').val();
alert(FirstTime); // 11 AM
alert(SecondTime);// 1 PM
var diff = (SecondTime - FirstTime); // Need value of 3 here..
I can have the time picker controls set to military time format and parse it to get the numbers out and get the difference. But thats not an option. I understand the numbers are getting saved as strings with the AM and PM attached.. is there a good way to do this?
Demo