找出日期差异JavaScript

Find out date difference JavaScript

本文关键字:JavaScript 日期      更新时间:2023-09-26

如何找出入住日期和退房日期的差异。

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);      
}

您可以使用Date.parse

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

JS小提琴

请看一下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)