-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
99 lines (95 loc) · 2.7 KB
/
index.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//現在時刻取得
var dt = new Date();
//年を抽出
var year = dt.getFullYear();
//月を抽出
var month = dt.getMonth()+1;
//曜日を抽出
var day = dt.getDay();
var today = dt.getDay();
//日にち
var date = dt.getDate();
//月の初めの曜日取得
var firstDate = new Date(year,month-1,1);
var firstDay= firstDate.getDay();
//月の最後の日を取得
var lastdate = new Date( year, month, 0);
var lastDate = lastdate.getDate();
console.log(firstDay);
console.log(lastDate)
var dayarray=[];
for(let i = 1; i<=42 ; i++){
if(i<=firstDay){
dayarray.push(" ");
}
else if(i<=firstDay+lastDate){
dayarray.push(i-firstDay);
}
else{
dayarray.push(" ");
};
};
console.log(dayarray)
window.onload = function () {
document.getElementById("susumu").onclick = function() {
dt= new Date(year,month,1);
console.log(dt)
year = dt.getFullYear();
month = dt.getMonth()+1;
date = dt.getDate();
firstDate = new Date(year,month-1,1);
firstDay= firstDate.getDay();
var lastdate = new Date( year, month, 0);
var lastDate = lastdate.getDate();
console.log(firstDay);
console.log(lastDate);
dayarray=[];
for(let i = 1; i<=42 ; i++){
if(i<=firstDay){
dayarray.push(" ");
}
else if(i<=firstDay+lastDate){
dayarray.push(i-firstDay);
}
else{
dayarray.push(" ");
};
};
for(let n = 0;n<=41;n++){
dayset(n)
};
document.getElementById("yearandmonth").textContent = `${String(month)}/${String(year)}`
};
document.getElementById("modoru").onclick = function(){
dt= new Date(year,month-2,1);
console.log(dt)
year = dt.getFullYear();
month = dt.getMonth()+1;
date = dt.getDate();
firstDate = new Date(year,month-1,1);
firstDay= firstDate.getDay();
var lastdate = new Date( year, month, 0);
var lastDate = lastdate.getDate();
console.log(firstDay);
console.log(lastDate);
dayarray=[];
for(let i = 1; i<=42 ; i++){
if(i<=firstDay){
dayarray.push(" ");
}
else if(i<=firstDay+lastDate){
dayarray.push(i-firstDay);
}
else{
dayarray.push(" ");
};
};
for(let n = 0;n<=41;n++){
dayset(n)
};
document.getElementById("yearandmonth").textContent = `${String(month)}/${String(year)}`;
};
};
function dayset(k){
document.getElementById(String(k+1)).textContent = String(dayarray[k]);
};