zoukankan      html  css  js  c++  java
  • js实现日期的相加减

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     <head>
      <title> New Document </title>
      <meta name="Generator" content="EditPlus">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
    
      <script type="text/javascript">
    
    function dateOperator(date,days,operator)
    
    {
    
        date = date.replace(/-/g,"/"); //更改日期格式
    	var nd = new Date(date);
    	nd = nd.valueOf();
    	if(operator=="+"){
    	 nd = nd + days * 24 * 60 * 60 * 1000;
    	}else if(operator=="-"){
    		nd = nd - days * 24 * 60 * 60 * 1000;
    	}else{
    		return false;
    	}
    	nd = new Date(nd);
    
    	var y = nd.getFullYear();
    	var m = nd.getMonth()+1;
    	var d = nd.getDate();
    	if(m <= 9) m = "0"+m;
    	if(d <= 9) d = "0"+d; 
    	var cdate = y+"-"+m+"-"+d;
    	return cdate;
    }
    
     
    
    //相减
    alert(dateOperator("2014-01-01",1,"-")) ;
    //相加
    alert(dateOperator("2014-01-01",1,"+")) ;
    
    </script> 
    
      </script>
     </head>
    
     <body>
      
     </body>
    </html>
    


  • 相关阅读:
    属性绑定与双向数据绑定
    vue基础
    tp5提交留言入库
    tp5表单提交
    TP5分页
    TP5模板与数据组合
    vue3.x使用Proxy做双向数据绑定总结
    vue2.x响应式原理总结
    HTML5移动端自适应解决方案
    springMVC实现文件上传
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3327535.html
Copyright © 2011-2022 走看看