forked from yuta-kawai/step1sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbirthday.js
More file actions
34 lines (27 loc) · 1.02 KB
/
Copy pathbirthday.js
File metadata and controls
34 lines (27 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function getBirthday () {
var year = document.getElementById("year").value;
var month = document.getElementById("month").value;
var day = document.getElementById("day").value;
return new Date(year, month - 1, day);
}
function getDateDiff(previous, latest) {
var diff = latest.getTime() - previous.getTime();
var days = Math.floor(diff / (1000 * 60 * 60 * 24));
diff -= days * (1000 * 60 * 60 * 24);
var hours = Math.floor(diff / (1000 * 60 * 60));
diff -= hours * (1000 * 60 * 60);
var mins = Math.floor(diff / (1000 * 60));
diff -= mins * (1000 * 60);
var seconds = Math.floor(diff / (1000));
diff -= seconds * (1000);
return {days:days, hours:hours, mins:mins, seconds:seconds};
}
function calculateBirthday() {
var now = new Date();
var birth = getBirthday();
var diff = getDateDiff(birth, now);
var message = "あなたが生まれてから" + diff.days + "日になりました!";
var result = document.getElementById("result");
result.textContent = message;
result.style.display = "";
}