javaScript计算两个日期相差天数
2016-03-31 14:22
639 查看
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <title></title> <script type="text/javascript"> function jiSanDays(endDate1){ var nowDate1=new Date(); var nowDate=new Date(nowDate1.getFullYear(),nowDate1.getMonth(),nowDate1.getDate()); var proDate=new Date(parseInt(endDate1.substring(0, 4),10),parseInt(endDate1.substring(4, 6),10)-1,parseInt(endDate1.substring(6, 8),10)); var days=parseInt(Math.abs(proDate -nowDate)/1000/60/60/24) if(proDate<nowDate){ days=0; } document.getElementById("wrapper").innerHTML=(proDate -nowDate)+"毫秒,相差天数"+days; } </script> </head> <body> <div id="wrapper">1111</div> <script> jiSanDays("20160410") </script> </body> </html>
总结:1、字符串转日期类型:
new Date(nowDate1.getFullYear(),nowDate1.getMonth(),nowDate1.getDate())
2、两个日期类型的相减的到的是毫秒值
相关文章推荐
- 判断浏览器JS
- initBinder解决Json日期转换为date类型
- console.log格式输出全解及console的其他方法
- Json对象与Json字符串互转(4种转换方式)
- Javascript和Ajax中文乱码吐血版解决方案
- 使用Jsoup 抓取页面的数据
- javascript中的this问题
- javascript处理HTML的Encode(转码)和Decode(解码)总结,避免js脚本注入问题
- jsp#0开发环境配置注意点
- Web报表工具FineReport的JS开发之字符串
- play的Json测试
- Web报表工具FineReport的JS开发之字符串
- 前置(后置)递增(递减)(读书笔记)
- VisJS 随机图
- 转 通过js获取cookie的实例及简单分析
- javascript 实现 接口编程
- JSON字符串转数组
- debugger调试
- Jsp的四大作用域与九大对象
- EF 序列化实体为Json时的循环引用问题(不用自己写实体,不用匿名类型,不用EF的上下文属性)