首页 > 编程开发 > JavaScript    日期:2020-05-27 / 浏览

代码如下:

<SCRIPT LANGUAGE="JavaScript"> 
<!-- 
//说明:这里用了Math.ceil()函数,向上取整,即零头算一天,^_^ 
var strDate1 = "2003-06-17 03:03:40.0"; 
var strDate2 = "2004-09-18 12:03:12.0"; 
strDate1=strDate1.substring(0,strDate1.lastIndexOf(".")).replace(/-/g,"/"); 
strDate2=strDate2.substring(0,strDate2.lastIndexOf(".")).replace(/-/g,"/"); 
var date1 = Date.parse(strDate1); 
var date2 = Date.parse(strDate2); 
alert("strDate2与strDate1相差"+Math.ceil((date2-date1)/(24*60*60*1000))+"天") 
//--> 
</SCRIPT> 
 
<SCRIPT LANGUAGE="JavaScript"> 
<!-- 
 
var strDate1 = "2004-09-17 03:03:00.0"; 
var strDate2 = "2004-09-17 04:05:00.0"; 
strDate1=strDate1.substring(0,strDate1.lastIndexOf(".")).replace(/-/g,"/"); 
strDate2=strDate2.substring(0,strDate2.lastIndexOf(".")).replace(/-/g,"/"); 
var date1 = Date.parse(strDate1); 
var date2 = Date.parse(strDate2); 
alert("strDate2与strDate1相差"+(date2-date1)/(60*60*1000)+"小时") 
//--> 
</SCRIPT>

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助~如果有疑问大家可以留言交流,谢谢大家对的支持!

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章