2013-04-29 36 views
-2

如何找出入住和退房日期之間的時間差。找出的時間差的JavaScript

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

什麼格式的輸入數據是看看嗎?輸出應該是什麼? – banzsh 2013-04-29 09:38:29

+0

檢查中: - 2013年4月30日,並檢查了: - 2013年5月3日 – 2013-04-29 09:40:53

+0

'VAR差異=新的日期(txtCheckoutNew) - 新的日期(txtCheckinNew);'? – Jashwant 2013-04-29 09:42:25

回答

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

請對 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)