js实现日期加1

访客9年前 (2017-07-06)javaScript4074

直接附代码

方法1:

<html>
<head>
   <script>
      function getLocalTime(addNum){//参数为加几天
  var today,ms,thatDay, y, m, d,endDate;
  today = new Date().getTime();
  ms = today + addNum*24*60*60*1000;
  thatDay = new Date(ms);
  y = thatDay.getFullYear();
  m = thatDay.getMonth()+1;
  d = thatDay.getDate();
  endDate = y+"-"+m+"-"+d;
  alert(endDate);
  //return endDate;
}
   </script>
</head>
<body>
 <input type='text'  id='a'  onclick="getLocalTime('1')"/>
</body>
<html>

方法2:

<html>
<head>
   <script>
      function getLocalTime(addNum){//参数为加几天
      var d2=document.getElementById("aa").value;    
      var arys= new Array();
      arys=d2.split('-');
       //得到日期类型
      var myDate = new Date(arys[0],arys[1],arys[2]); 
      myDate=myDate.valueOf();         
      myDate=myDate +addNum * 24 * 60 * 60 * 1000;
      myDate = new Date(myDate);
      alert(myDate.getFullYear() + "-" + (myDate.getMonth()) + "-" + myDate.getDate() );
}
   </script>
</head>
<body>
 <input type='text'  id='aa' value='2017-7-5' onclick="getLocalTime('1')"/>
</body>
<html>

本文原创,转载必追究版权。

分享给朋友:

相关文章

js动态加载复选框checkbox(XML串)

 首先,使用JS动态产生Checkbox可以采用如下类似的语句:代码如下:var checkBox=document.createElement("input");che...

MyEclipse 10 性能大优化

MyEclipse 10 性能大优化

 MyEclipse 10已发布,新版本的特性能够大大提高开发者的效率。但同时,由于电脑配置的原因,很多开发者在使用MyEclipse的时候,速度都不是很快,需要我们对MyEclipse进行...

jquery 操作html元素(及CSS)

jquery 操作html元素(及CSS)

 $("li").addClass("aui-user-view-cell aui-img") ;  //给元素添加样式$('#a1...

竟然可以这样打扮!女人呆了!男人痴了!

来个轻松点的哇,惊呆了,肯定贵不了,立刻去瞅瞅...

程序员为什么不炫富

程序员为什么不炫富

 提到互联网,尤其是互联网工程师们,人们往往会想到两个词:“高薪”和“高压”。在知乎上“为什么很少见工资高的程序员炫富?”的问题下,一个得票很高的答案是:“乐意炫富的人,不是因为有钱,而是因为付出的少...

dwz +jfinal 批量多文件上传 实例

页面部分:<link href="${root}/style/dwz/uploadify/css/uploadify.css" rel="sty...

评论列表

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。