JavaScript getTimeによる日付計算

date(year, month, day)をgetTime()で取得し、1000(ミリ秒) * 60(秒) * 60(分) * 24(時間)で割ります。 

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <title>日付計算の練習</title>
    <style>
    body {

    }
    </style>
  </head>
  <body>
    <h1>日付計算の練習</h1>
    <p>誕生日: <input type="text" name="birthday" id="birthday" value="1990-04-01"></p>
    <p><input type="button" value="計算!" onclick="getAge();"></p>
    <p>生まれてから<span id="daysPast">???</span>日経過していて、およそ<span id="age">???</span>歳です!</p>
    <script>
      function getAge(){
          var birthday = document.getElementById('birthday').value.split("-");

          var d1 = new Date(birthday[0], birthday[1]-1, birthday[2])
          var d2 = new Date();
          var diff = d2.getTime() - d1.getTime();
          var daysPast = Math.floor(diff / (1000 * 60 * 60 * 24));
          var age = Math.floor(daysPast / 365.25);

          document.getElementById('daysPast').innerHTML = daysPast;
          document.getElementById('age').innerHTML = age;
      }
    </script>
  </body>
</html>