jQuery Time difference
<p>Hi am making some time calculation in jquery. Do you think am using the best way?</p>

<pre><code>&lt;table width="100%" border="0" cellpadding="0"&gt;
    &lt;tr&gt;
        &lt;td&gt;Departure Time&lt;/td&gt;
        &lt;td&gt;Arrival Time&lt;/td&gt;
        &lt;td&gt;Difference&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;&lt;input name="departure" type="text" class="std1" id="departure"  size="10" alt="time"/&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input name="arrival" type="text" class="std1" id="arrival" size="10" alt="time"/&gt;&lt;/td&gt;
        &lt;td&gt;&lt;input name="duration" type="text" class="std" id="duration" size="10" readonly="readonly" alt="time"/&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;


function hour2mins(timestr) {
    var spltd = timestr.split(":");
    if (spltd.length == 2) {
        return parseInt(parseInt(spltd[0] * 60) + parseInt(spltd[1]));
    } else {
        return false;
    }
}

function mins2hour(instr) {
    var hourstr = parseInt(instr / 60);
    if (hourstr.toString().length == 1) {
        hourstr = "0" + (hourstr + '');
    }
    var minstr = parseInt(instr % 60);
    if (minstr.toString().length == 1) {
        minstr = "0" + (minstr + '');
    }
    return hourstr + ':' + minstr;
}

function tdiff(t1, t2) {
    var t1 = hour2mins(t1);
    var t2 = hour2mins(t2);
    var ret = mins2hour(parseInt(t2 - t1));
    if (t2 &lt; t1) {
        ret = mins2hour(parseInt(parseInt(t2 + 1440) - t1));
    }
    return ret;
}

$(function() {
    $("input.std1").keyup(function(b) {
        $("#duration").val(tdiff($("#departure").val(), $("#arrival").val()));
    });
});
</code></pre>

<p>link : <a href="http://jsfiddle.net/xmQD7/1/" rel="nofollow">http://jsfiddle.net/xmQD7/1/</a></p>
