找出日期差异JavaScript

时间:2013-04-29 09:37:28

标签: javascript jquery date

如何查明登记入住和退房日期之间的日期差异。

function Checkdate(id)
{
  var txtCheckinNew = $(id).parents("table").find("#[id$=TransferDate]").val(); //04/30/2013
  var txtCheckoutNew =$(id).parents("table").find("#[id$=TransferDate1]").val(); //05/03/2013
  var diff =   Date(txtCheckoutNew) - Date(txtCheckinNew);
  alert(diff);      
}

2 个答案:

答案 0 :(得分:1)

您可以使用Date.parse

var txtCheckinNew = Date.parse($('#TransferDate').val());
var txtCheckoutNew = Date.parse($('#TransferDate1').val());
alert((txtCheckoutNew-txtCheckinNew)/(24*60*60*1000));

JS Fiddle

答案 1 :(得分:1)

请看一下 http://jsfiddle.net/2dJAN/1/

<div class="date"></div>

var Date1 = new Date (2008, 7, 25);
var Date2 = new Date (2008, 7, 27);
var one_day = 1000*60*60*24;
var Days = (Date2.getTime() - Date1.getTime())/(one_day)
$('.date').html(Days)