gpt4 book ai didi

javascript - 使用javascript计算两个日期之间的天数

转载 作者:行者123 更新时间:2023-11-28 09:48:57 25 4
gpt4 key购买 nike

<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
<script type="text/javascript" src="jsDatePick.min.1.3.js"> </script>
<script type="text/javascript">
window.onload = function(){
var fromObj,toObj;
fromObj=new JsDatePick({
useMode:2, target:"inputField1",dateFormat:"%d-%M-%Y"

});
toObj=new JsDatePick({
useMode:2,
target:"inputField2",
dateFormat:"%d-%M-%Y"

});

function viewAlert(){
//what i need to put it here?

}

};
</script>
</head>
<body>
<form name="form1">

<table align="center">
<tr><td>from:</td><td><input type="text" size="12" id="inputField1" name="from" /></td></tr>
<tr><td>to:</td><td><input type="text" size="12" id="inputField2" name="to" onblur="viewAlert()" /></td></tr>
</table>

</form>

我创建了两个输入字段,它们从 jsDatePicker 获取日期。输入这些日期后,我需要在警报框中显示所选日期的黑白天数。为此我需要做什么?

提前致谢

最佳答案

var msDay = 24*60*60*1000; 
var days = Math.round(Math.abs((fromObj.getTime() - toObj.getTime())/(msDay )));

关于javascript - 使用javascript计算两个日期之间的天数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11360277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com