javascript 日期相减-在线教程(附代码)
代码如下:
<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>
相关推荐
softwear 2020-08-21
ZGCdemo 2020-08-16
northwindx 2020-05-31
zrtlin 2020-11-09
xuebingnan 2020-11-05
wikiwater 2020-10-27
heheeheh 2020-10-19
Crazyshark 2020-09-15
jczwilliam 2020-08-16
littleFatty 2020-08-16
idning 2020-08-03
jinxiutong 2020-07-26
lanzhusiyu 2020-07-19
Skyline 2020-07-04
xiaofanguan 2020-06-25
Aveiox 2020-06-23