박지환

Add d-day count in ejs

1 -const today = new Date("2022-05-12"); //오늘 날짜 입력 1 +const today = new Date(); //오늘 날짜 입력
2 const holiday = new Date("2022-10-01"); //공휴일 날짜 입력 2 const holiday = new Date("2022-10-01"); //공휴일 날짜 입력
3 -
4 -const diffDate= today.getTime() - holiday.getTime();
5 -
6 -const dday= Math.abs(diffDate / (1000 * 3600 * 24));
7 -
8 -console.log(dday);
...\ No newline at end of file ...\ No newline at end of file
3 +
4 +console.log(today.getMonth() + 1);
5 +
6 +const diffDate = today.getTime() - holiday.getTime();
7 +
8 +const dday = Math.abs(diffDate / (1000 * 3600 * 24));
9 +
10 +console.log(dday);
......
...@@ -76,22 +76,30 @@ function init() { ...@@ -76,22 +76,30 @@ function init() {
76 } 76 }
77 let i = 0; 77 let i = 0;
78 let length = dateName.length; 78 let length = dateName.length;
79 - while (i < length){ 79 + var holiArr = [];
80 + while (i < length) {
80 var temptoday = dateName[i]; 81 var temptoday = dateName[i];
81 var tempdate = locdate[i]; 82 var tempdate = locdate[i];
82 - var modifiedDate = tempdate.substr(0,4) + '-' + tempdate.substr(4,2) + '-' + tempdate.substr(6,2); 83 + var modifiedDate =
84 + tempdate.substr(0, 4) +
85 + "-" +
86 + tempdate.substr(4, 2) +
87 + "-" +
88 + tempdate.substr(6, 2);
83 var today = new Date("2022-05-13"); //오늘 날짜 입력 89 var today = new Date("2022-05-13"); //오늘 날짜 입력
84 var holiday = new Date(modifiedDate); //공휴일 날짜 입력 90 var holiday = new Date(modifiedDate); //공휴일 날짜 입력
85 - var diffDate= today.getTime() - holiday.getTime(); 91 + var diffDate = today.getTime() - holiday.getTime();
86 - var dday= Math.abs(diffDate / (1000 * 3600 * 24)); 92 + var dday = Math.abs(diffDate / (1000 * 3600 * 24));
87 - console.log(temptoday + "까지 " + dday +"일 남았습니다."); 93 + console.log(temptoday + "까지 " + dday + "일 남았습니다.");
94 + holiArr.push(dday);
88 i++; 95 i++;
89 - } 96 + }
90 console.log(locdate); 97 console.log(locdate);
91 // Create tempArr to save dateName and locdate at once 98 // Create tempArr to save dateName and locdate at once
92 tempArr = []; 99 tempArr = [];
93 tempArr.push(dateName); 100 tempArr.push(dateName);
94 tempArr.push(locdate); 101 tempArr.push(locdate);
102 + tempArr.push(holiArr);
95 console.log(tempArr); 103 console.log(tempArr);
96 }); 104 });
97 } 105 }
...@@ -99,8 +107,6 @@ function init() { ...@@ -99,8 +107,6 @@ function init() {
99 }); 107 });
100 } 108 }
101 109
102 -
103 -
104 app.get("/", function (req, res) { 110 app.get("/", function (req, res) {
105 init(); 111 init();
106 // Send data from nodejs to ejs 112 // Send data from nodejs to ejs
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
11 <body> 11 <body>
12 <% for(var i = 0; i < data[0].length; i++) {%> 12 <% for(var i = 0; i < data[0].length; i++) {%>
13 <p> 13 <p>
14 - <h1><%= data[0][i] %> <%= data[1][i] %></h1> 14 + <h1><%= data[0][i] %> <%= data[1][i] %> <%= data[2][i] %>일 남았습니다.</h1>
15 </p> 15 </p>
16 <% } %> 16 <% } %>
17 </body> 17 </body>
......