박지환

Add d-day count in ejs

const today = new Date("2022-05-12"); //오늘 날짜 입력
const today = new Date(); //오늘 날짜 입력
const holiday = new Date("2022-10-01"); //공휴일 날짜 입력
const diffDate= today.getTime() - holiday.getTime();
const dday= Math.abs(diffDate / (1000 * 3600 * 24));
console.log(dday);
\ No newline at end of file
console.log(today.getMonth() + 1);
const diffDate = today.getTime() - holiday.getTime();
const dday = Math.abs(diffDate / (1000 * 3600 * 24));
console.log(dday);
......
......@@ -76,22 +76,30 @@ function init() {
}
let i = 0;
let length = dateName.length;
while (i < length){
var holiArr = [];
while (i < length) {
var temptoday = dateName[i];
var tempdate = locdate[i];
var modifiedDate = tempdate.substr(0,4) + '-' + tempdate.substr(4,2) + '-' + tempdate.substr(6,2);
var modifiedDate =
tempdate.substr(0, 4) +
"-" +
tempdate.substr(4, 2) +
"-" +
tempdate.substr(6, 2);
var today = new Date("2022-05-13"); //오늘 날짜 입력
var holiday = new Date(modifiedDate); //공휴일 날짜 입력
var diffDate= today.getTime() - holiday.getTime();
var dday= Math.abs(diffDate / (1000 * 3600 * 24));
console.log(temptoday + "까지 " + dday +"일 남았습니다.");
var diffDate = today.getTime() - holiday.getTime();
var dday = Math.abs(diffDate / (1000 * 3600 * 24));
console.log(temptoday + "까지 " + dday + "일 남았습니다.");
holiArr.push(dday);
i++;
}
}
console.log(locdate);
// Create tempArr to save dateName and locdate at once
tempArr = [];
tempArr.push(dateName);
tempArr.push(locdate);
tempArr.push(holiArr);
console.log(tempArr);
});
}
......@@ -99,8 +107,6 @@ function init() {
});
}
app.get("/", function (req, res) {
init();
// Send data from nodejs to ejs
......
......@@ -11,7 +11,7 @@
<body>
<% for(var i = 0; i < data[0].length; i++) {%>
<p>
<h1><%= data[0][i] %> <%= data[1][i] %></h1>
<h1><%= data[0][i] %> <%= data[1][i] %> <%= data[2][i] %>일 남았습니다.</h1>
</p>
<% } %>
</body>
......