미채택 완료

시간 차이를 실시간으로 표여 주고 싶습니다.

output1, output2 버튼을 클릭하면 현재 시간이 나옵니다.

output3 에 output1, output2 차이를 분으로 실기간으로 나오게 할려면 어떻게 해야할까요?

 

 

 

 

Copy
<script>
function now_time() {
    var time_t = new Date();
    var s =
    set_standard(time_t .getHours(), 2)+':'+
    set_standard(time_t .getMinutes(), 2);
    document.getElementById("output1").value = s;
}

function now_time2() {
    var time_t = new Date();
    var s =
    set_standard(time_t .getHours(), 2)+':'+
    set_standard(time_t .getMinutes(), 2);
    document.getElementById("output2").value = s;
}

function set_standard(time, digits) {
    var zero = '';
    time = time.toString();
    if (time.length < digits) {
        for (i = 0; i < digits - time.length; i++)
        zero += '0';
    }
    return zero + time;
}
</script>        

            
<td>
<input type="text" name="output1" id="output1" value="<?php echo $write['output1']; ?>">
<input type="button" onclick="now_time(this);"value="시작 시간">
</td>
<td>
<input type="text" name="output2" id="output2" value="<?php echo $write['output2']; ?>">
<input type="button" onclick="now_time2(this);" value="종료 시간">
</td>
<td>
<input type="text" name="output3" id="output3" value="<?php echo $write['output3']; ?>">
</td>
|

답변 2개

now_time() 함수와 
now_time2() 함수에

두군데 값이 존재하는지 여부를 체크해서 두군데 값이 기입이 되어 있다면 값을 체크해서 표기해주시면 될듯 합니다.

setInterval(clock, 1000); // 1초마다 실행

 

clock함수를 1초간격으로 호출하시면됩니다. 

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