[短代码]JS日期加天数得到新日期
最后更新: 2015-07-12
浏览次数:
以下代码可以直接保存问HTML运行.
或给大家推荐一个在线调试代码的网站: http://jsbin.com/
或给大家推荐一个在线调试代码的网站: http://jsbin.com/
![[短代码]JS日期加天数得到新日期](/uploads/allimg/150712/2-150G2163331.png)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> <script type="text/javascript"> function getdate() { var stdate=document.getElementById("stdate").value+""; var sumdate=document.getElementById("sumdate").value; var eddate=document.getElementById("eddate"); var a = new Date(stdate) a = a.valueOf() a = a +sumdate * 24 * 60 * 60 * 1000 a = new Date(a) eddate.innerHTML=a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日"; } </script> </head> <body> (提示:日期格式为:2015/8/22)<br /> 开始日期:<input type="text" id="stdate" value="2015/8/22" />+<input type="text" id="sumdate" value="45" />天数=<span id="eddate"></span> <input type="button" id="stdate" value="计算" onclick="getdate()" /> </body> </html> |