function remaindTime() {
var now = new Date();
var end = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate(),
15,
00,
00
);
var nt = now.getTime();
var et = end.getTime();
sec = parseInt(et - nt) / 1000;
day = parseInt(sec / 60 / 60 / 24);
sec = sec - day * 60 * 60 * 24;
hour = parseInt(sec / 60 / 60);
sec = sec - hour * 60 * 60;
min = parseInt(sec / 60);
sec = parseInt(sec - min * 60);
var day = now.getDay();
// console.log(day);
if (hour <= 0 && min <= 0 && sec <= 0) {
$(".hours").html("행사가 종료되었습니다.");
$(".col").html("");
} else {
$(".hours").html("행사 종료 마감시까지 " + hour + "시간");
$(".minutes").html(min + "분");
$(".seconds").html(sec + "초 남았습니다.");
}
}
setInterval(remaindTime, 1000);
});
이걸 주말이나 공휴일에는 노출을 안시키려고 하는데요 뭘 추가해야 할지 모르겠어요
답변 2개 / 댓글 2개
today = new Date();
if (today.getDay() % 6 === 0) {
alert("주말(토,일)에는 글쓰기를 할 수 없습니다");
location.href = "이동할 페이지 주소";
}
주말이 아닌 공휴일의 경우
holiday = ["3:1", "8:15", "12:25", ......] 등으로 공휴일을 배열에 담아서
today.getMonth() + 1 + ":" + today.getDate() 와 일치할 경우 마찬가지로 튕겨내는 코드를 적용해 주세요.
그래서 최종코드는
<script>
holiday = ["3:1", "8:15", "12:25"];
today = new Date();
if (today.getDay() % 6 === 0) {
alert("주말(토,일)에는 글쓰기를 할 수 없습니다");
location.href = "이동할 페이지 주소";
}
for (i in holiday) if (holiday[i] === today.getMonth() + 1 + ":" + today.getDate()) {
alert("공휴일에는 글쓰기를 할 수 없습니다");
location.href = "이동할 페이지 주소";
}
</script>
답변에 대한 댓글 1개
주말은 date(w) 부분을 참고하셔서 적용하시면 되시는데
공휴일은 별도로 공휴일 일정을 설정해서 처리되도록 수정해야 하는 부분이 있습니다.
일단 주말에 관련 부분은 참고 주소 드릴테니 참고하셔서 적용하시면 됩니다.
참고: https://www.habonyphp.com/2020/07/php-date.html
답변에 대한 댓글 1개
답변을 작성하려면 로그인이 필요합니다.