jquery 计算两个日期相差的天数

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <meta charset = "utf-8">
 5     <title></title>
 6 </head>
 7 <body>
 8     <input type="text" id="txt1" value="2018-05-10"/>
 9     <input type="text" id="txt2" value="2018-05-11"/>
10     <input type="button"  id="btn" value="点击">
11 </body>
12 
13 <script type="text/javascript" src="jquery.js"></script>
14 <script type="text/javascript">
15     
16 $(document).ready(function() {
17 
18     $("#btn").click(function(){
19 
20         var start=$("#txt1").val();
21         var end=$("#txt2").val();
22         
23         start=start.replace(/-/g,"/");
24 
25         var startdate=new Date(start);
26         end=end.replace(/-/g,"/");
27         var enddate=new Date(end);
28 
29         var time=enddate.getTime()-startdate.getTime();
30         var days=parseInt(time/(1000 * 60 * 60 * 24));
31     });
32 });
33 </script>
34 </html>

 

posted @ 2018-05-10 18:42  ysx_小鱼  阅读(999)  评论(0编辑  收藏  举报