1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">    
  3.   
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">    
  5. <head>  
  6.   <script type="text/javascript">  
  7.     var getOffDays = function(startDate, endDate) {   
  8.     var mmSec = (endDate.getTime() - startDate.getTime()); //得到时间戳相减 得到以毫秒为单位的差   
  9.       return (mmSec / 3600000 / 24); //单位转换为天并返回   
  10.     };   
  11.     alert(getOffDays(new Date(2009,1,1), new Date(2009,2,1)));   
  12.     alert(getOffDays(new Date(2009,2,1), new Date(2009,3,1)));   
  13.     alert(getOffDays(new Date(2009,11,1), new Date(2009,12,1)));   
  14.     alert(getOffDays(new Date(2009,11,10), new Date(2009,12,10)));   
  15.   </script>  
  16. </head>  
  17. <body>  
  18. </body>  
  19. </html>  
posted on 2010-09-16 08:44  vibratea  阅读(512)  评论(0编辑  收藏  举报