[CODE]
데브피아 : 안대환님 글
경매 잔여 시간이 클라이언트쪽 기준으로 남는것은 예제를 많이 보았다.
서버측의 시간을 기준으로 하여 잔여시간을 실시간으로 discounting 하는 예제를 올릴까한다.
대략 설명
1.서버 기준 시간은 ms-sql의 함수를 사용하여 쿼리하여 가져온다.
2.자바스크립에서 재귀적 호출하여 1초단위로 디스카운팅한다.
<!--#include virtual="/dbconn.asp" -->
<html>
<script language="javascript">
function getRemainedSellTime(endDateTime, currentDttm) {
var endYyyy = Number(endDateTime.substring(0,4));
var endMm = Number(endDateTime.substring(4,6)) - 1;
var endDd = Number(endDateTime.substring(6,8));
var endHh = Number(endDateTime.substring(8,10));
var endMi = Number(endDateTime.substring(10,12));
var endSs = Number(endDateTime.substring(12,14));
var nowDateTime = String(currentDttm);
var nowYyyy = Number(nowDateTime.substring(0,4));
var nowMm = Number(nowDateTime.substring(4,6)) - 1;
var nowDd = Number(nowDateTime.substring(6,8));
var nowHh = Number(nowDateTime.substring(8,10));
var nowMi = Number(nowDateTime.substring(10,12));
var nowSs = Number(nowDateTime.substring(12,14));
//now = new Date();
now = new Date(nowYyyy, nowMm, nowDd, nowHh, nowMi, nowSs); //현재시간 지정
later = new Date(endYyyy, endMm, endDd, endHh, endMi, endSs); //완료시간 지정
if( later <= now ) {
s2.innerHTML = "0";
return;
}
days = (later - now) / 1000 / 60 / 60 / 24;
daysRound = Math.floor(days);
hours = (later - now) / 1000 / 60 / 60 - (24 * daysRound);
hoursRound = Math.floor(hours);
minutes = (later - now) / 1000 /60 - (24 * 60 * daysRound) - (60 * hoursRound);
minutesRound = Math.floor(minutes);
seconds = (later - now) / 1000 - (24 * 60 * 60 * daysRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
secondsRound = Math.round(seconds);
if (secondsRound <= 9) {
s1.innerHTML = "0";
s2.innerHTML = secondsRound;
} else {
s1.innerHTML = Math.floor(secondsRound/10);
s2.innerHTML = secondsRound%10;
}
if (minutesRound <= 9) {
m1.innerHTML = "0";
m2.innerHTML = minutesRound;
} else {
m1.innerHTML = Math.floor(minutesRound/10);
m2.innerHTML = minutesRound%10;
}
if (hoursRound <= 9) {
h1.innerHTML = "0";
h2.innerHTML = hoursRound;
} else {
h1.innerHTML = Math.floor(hoursRound/10);
h2.innerHTML = hoursRound%10;
}
if (daysRound <= 9) { //한자리일때
d1.innerHTML = "";
d2.innerHTML = "";
d3.innerHTML = daysRound;
} else if (daysRound <= 99) { //두자리일때
d1.innerHTML = "";
d2.innerHTML = Math.floor((daysRound/10)%10);
d3.innerHTML = Math.floor(daysRound%10);
} else if (daysRound <= 999) { //세자리일때
d1.innerHTML = Math.floor(daysRound/100);
d2.innerHTML = Math.floor((daysRound/10)%10);
d3.innerHTML = Math.floor(daysRound%10);
}
currentDttm = parseInt(currentDttm) + 1;
newtime = window.setTimeout("getRemainedSellTime('" + endDateTime + "','" + currentDttm +"');", 1000);
}
</script>
<body>
<%
sql = "select CONVERT(varchar(20), getdate(),101),CONVERT(varchar(20), getdate(),108);"
Set tt = db.execute(sql)
tt_all = tt(0)&tt(1) '07/17/200408:19:16 형태로 가져옴,형태는 어떻게 가져오던지 맘대로 하세요.
tt_yy = mid(tt_all,7,4) '년
tt_mm = mid(tt_all,1,2) '월
tt_dd = mid(tt_all,4,2) '일
tt_hh = mid(tt_all,11,2) '시
tt_mi = mid(tt_all,14,2) '분
tt_se = mid(tt_all,17,2) '초
cur_time = tt_yy&tt_mm&tt_dd&tt_hh&tt_mi&tt_se '서버측 현재 시간 DB 기준 20040717093310
%>
<%d_day = "20050717072000" '경매종료시간%>
<html>
<HEAD>
<title>경매종료시간</title>
</HEAD>
<center>
경매 잔여 시간<br/><br/>
<center>
<font id="d1">0</font><font id="d2">0</font><font id="d3">0</font>일
<font id="h1">0</font><font id="h2">0</font>시간
<font id="m1">0</font><font id="m2">0</font>분
<font id="s1">0</font><font id="s2">0</font>초
<script>getRemainedSellTime('<%=d_day%>', '<%=cur_time%>');</script>
</center>
</body>
</html>
</body>
</html>
[/CODE]
MAXTOR 15000RPM
SEGATE 15000RPM 2EA RAID0
SEGATE 15000RPM 2EA RAID0
vmware gsx server입니다.
서버및 프로그램 테스트할때 유용하게 사용하고있습니다.