Possible Duplicate:
check time difference in javascript
calculate time difference in javascript
this is my block of code to pull times from a form input,
start = group.find('.startTime').val().replace(':',''), // like 0100
end = group.find('.endTime').val().replace(':',''), // like 0300
timeDiff = (end - start) < 0 ? (end - start + 2400) : (end - start),
timeDiff
accounts for times passing midnight, so like if I try and subtract 2300 from 0100, and get -2200, it adds the 2400 to get the correct difference of 0200, or 2 hours.
my problem arises where i try to subtract some times like 2100 - 2030 (which should give me a half hour) but because its just a raw number i get the actual difference of 70. my question is how would I correctly subtract these? If i need to convert it to a date or time object what would be the proper way of doing so? I looked into the setTime
method but that didn't sound like what i needed.
Thanks in advance.