채택완료

판매종료시간에 대해서 문의있습니다.

홈쇼핑 홈페이지 만드는 도중 

 

판매시간 설정에 대해 구현할려고 합니다.

 

필드값을   "시작판매시간" 과 "종료시간"을 만들어서

 

판매시각 이전에는 

 

document.from값.name값.value = "  상품 개시 남은 시간   상품 시작 시간표시 "; 

 

판매 시각 중이라면 

 

document.from값.name값.value = "  상품 개시 남은 시간   종료되는 시간표시 ";

 

판매 시각이 완료되면

 

document.from값.name값.value = "  상품 개시 남은 시간   해당 상품은 종료되었습니다. ";

 

이렇게 빨간색 표시되는곳에 카운트 다운 시간을 표시 할려고 합니다.

 

그럼 소스를 보여드리자면

 

Copy
<html><HEAD><title>판매종료시간</title><SCRIPT type="text/javascript"><!--function reverse_counter(){today = new Date();start_d_day = new Date("jul 10 2014 00:00:00");start_days = (start_d_day - today) / 1000 / 60 / 60 / 24;start_daysRound = Math.floor(start_days);start_hours = (start_d_day - today) / 1000 / 60 / 60 - (24 * start_daysRound);start_hoursRound = Math.floor(start_hours);start_minutes = (start_d_day - today) / 1000 /60 - (24 * 60 * start_daysRound) - (60 * start_hoursRound);start_minutesRound = Math.floor(start_minutes);start_seconds = (start_d_day - today) / 1000 - (24 * 60 * 60 * start_daysRound) - (60 * 60 * start_hoursRound) - (60 * start_minutesRound);start_secondsRound = Math.round(start_seconds);end_d_day = new Date("jul 12 2014 00:00:00");end_days = (end_d_day - today) / 1000 / 60 / 60 / 24;end_daysRound = Math.floor(end_days);end_hours = (end_d_day - today) / 1000 / 60 / 60 - (24 * end_daysRound);end_hoursRound = Math.floor(end_hours);end_minutes = (end_d_day - today) / 1000 /60 - (24 * 60 * end_daysRound) - (60 * end_hoursRound);end_minutesRound = Math.floor(end_minutes);end_seconds = (end_d_day - today) / 1000 - (24 * 60 * 60 * end_daysRound) - (60 * 60 * end_hoursRound) - (60 * end_minutesRound);end_secondsRound = Math.round(end_seconds);sec = " 초."min = " 분, "hr = " 시간, "dy = " 일, "if(start_daysRound > 0 || start_hoursRound > 0 || start_minutesRound > 0 || start_secondsRound > 0)    <--이부분 ㅠ,ㅠ{ document.counter.counter_box.value = "  상품 개시 남은 시간 :   " + start_daysRound  + dy + start_hoursRound + hr + start_minutesRound + min + start_secondsRound + sec;newtime = window.setTimeout("reverse_counter();", 1000);return; }else if(end_daysRound > 0) { document.counter.counter_box.value = "  홈페이지 개장일까지 남은 시간 :   " + end_daysRound  + dy + end_hoursRound + hr + end_minutesRound + min + end_secondsRound + sec;newtime = window.setTimeout("reverse_counter();", 1000);  return; }else{//일:0 시간:0 분:0 초:0 이라면 종료메세지 출력 document.counter.counter_box.value = '경매가 종료되었습니다.'; }} //--></script></HEAD><BODY onLoad="reverse_counter()"><center><form name="counter">    <input type="text" name="counter_box" size="55" ></form></center></body></html>

 

일단 전체적으로 소스를 만들었는데


어떤 경우에 시간을 계산에서 if문에 상품 개시 남은 시간으로 표시할지

 

아니면 판매 종료된건지

 

아니면 판매 중인지

 

여러가지 시간을 계산해야되는데 ㅠ,ㅠ

 

잘 안되네요 ㅠ,ㅠ

 

지금 현재 시간을 불러와서 계산할려고 하자니 

 

자바스크립트 안에는 new Date();​ 로 표현할수 있는데

 

이것은  php 처럼 date("Y-m-d H:i:s")로 표현이 되는게 아니라.ㅠ,.ㅠ


if문 else if문 else을 


어떻게 표현 하면 좋을까요?


긴글 읽어줘서 감사합니다 ㅠ,ㅠ

 





답변 1개

채택된 답변
+20 포인트

Copy
if (today < start_d_day) { } else if (start_d_day <= today && today <= end_d_day) {} else {}

답변을 작성하려면 로그인이 필요합니다.