title: show duration between two times using javascript in asp.net
body: <p>i have asp.net web application with user-control having two text boxes to which i have assigned timepicker property's through java script.
  i need to find duration between two time (between two text boxes) through java-script when any of the textbox value changes and set that duration value to label.
  Overall,My user-control contain two text-boxes and one label. 
  However i have tried but not able display duration in label.</p>
  
  <p>This my javascript:---</p>
  
  <pre><code>&lt;script type="text/javascript" src="js/jquery.timePicker.js"&gt;&lt;/script&gt;
  &lt;script type="text/JavaScript"&gt;
    jQuery(function() {
  $("#&lt;%=time3.ClientID %&gt;, #&lt;%=time4.ClientID %&gt;").timePicker();
  
    // Store time used by duration.
    var oldTime = $.timePicker("#&lt;%=time3.ClientID %&gt;").getTime();
    // Keep the duration between the two inputs.
  
    $("#&lt;%=time3.ClientID %&gt;").change(function() {
        if ($("#&lt;%=time4.ClientID %&gt;").val()) { // Only update when second input has a value.
  
            // Calculate duration.
            var duration = ($.timePicker("#&lt;%=time4.ClientID %&gt;").getTime() - oldTime);
           ($.timePicker("#&lt;%=txtTimeDiff.ClientID %&gt;").setTime(new Date(duration)));
            var time = $.timePicker("#&lt;%=time3.ClientID %&gt;").getTime();
            // Calculate and update the time in the second input.
            $.timePicker("#&lt;%=time4.ClientID %&gt;").setTime(new Date(new Date(time.getTime() + duration)));
            oldTime = time;
  
        }
    });
    // Validate.
    $("#&lt;%=time4.ClientID %&gt;").change(function() {
        if ($.timePicker("#&lt;%=time3.ClientID %&gt;").getTime() &gt; $.timePicker(this).getTime()) {
            $(this).addClass("error");
        }
        else {
            $(this).removeClass("error");
        }
    });
  });
  </code></pre>
  
  <p>My controls:-----</p>
  
  <pre><code>&lt;asp:TextBox ID="time3" Width="50px" Text="09:00"  runat="server" Height="19px"&gt;&lt;/asp:TextBox&gt;
  &lt;asp:TextBox ID="time4" Width="50px" Text="09:00"  runat="server" Height="19px"&gt;&lt;/asp:TextBox&gt;
  &lt;asp:Label ID="txtTimeDiff" Width="50px" Text="" runat="server" Height="18px"&gt;&lt;/asp:Label&gt;
  </code></pre>