SOURCE

console 命令行工具 X clear

                    
>
console
var hzWeek = new Array("日", "一", "二", "三", "四", "五", "六", "日");
function cweekday(wday) {
  return hzWeek[wday];
}

function cala() {
  y = document.getElementById("SY").value;
  m = document.getElementById("SM").value;
  d = document.getElementById("SD").value;
  ddd = document.getElementById("decday").value;

  ttt = new Date(y, m - 1, d).getTime() + ddd * 24000 * 3600;

  theday = new Date();
  theday.setTime(ttt);

  document.getElementById("result1").innerHTML = theday.getFullYear() + "年" + (1 + theday.getMonth()) + "月" + theday.getDate() + "日" + "星期" + cweekday(theday.getDay());

}

function calb() {

  y2 = document.getElementById("SY2").value;
  m2 = document.getElementById("SM2").value;
  d2 = document.getElementById("SD2").value;

  y3 = document.getElementById("SY3").value;
  m3 = document.getElementById("SM3").value;
  d3 = document.getElementById("SD3").value;

  day2 = new Date(y2, m2 - 1, d2);
  day3 = new Date(y3, m3 - 1, d3);

  document.getElementById("result2").innerHTML = (day3 - day2) / 86400000;

}
<div class="main">
  <h2>
    推算几天后的日期:
  </h2>
  <br>
   和
  <input size=8 id=SY value=2016>
  年
  <input size=4 id=SM value=12>
  月
  <input size=4 id=SD value=15>
  日 (缺省为今天)
  <br>
  相差
  <input size=8 id=decday value=100>
  天 (输入负数则往前计算)
  <br>
  是:
  <span id=result1>
  </span>
  <br>
  <button onclick="cala()">
    计算
  </button>
  <br>
  <br>
  <h2>
    计算日期差:
  </h2>
  <br>
    
  <input size=8 id=SY2 value=2016>
  年
  <input size=4 id=SM2 value=12>
  月
  <input size=4 id=SD2 value=15>
  日
  <br>
  和 
  <input size=8 id=SY3 value=2017>
  年
  <input size=4 id=SM3 value=1>
  月
  <input size=4 id=SD3 value=1>
  日
  <br>
  相差:
  <span id=result2>
  </span>
  天
  <br>
  <button onclick="calb()">
    计算
  </button>
  <div>
.main {
  font-size: 14px;
  width: 450px;
  margin: auto;
  background: #FFF;
  padding: 20px;
  margin-top: 100px;
  border-radius: 10px;
  box-shadow: 0px 1px 10px rgba(0, 0, 0, 0.35);
}

button {
  border: none;
  outline: none;
  padding: 11px 32px;
  font-size: 14px;
  background: #444444;
  box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.75);
  color: #FFF;
  border-radius: 27px;
  margin: auto;
  display: block;
  font-weight: 800;
}