2016-07-20
특정 시간을 기준으로 1초마다 흘러가는 함수를 만들어 보았다.
<div name="time_show_div"></div>

<script>

var tl = new Date();
var tt = new Date("<?php=date('Y-m-d H:i:s')?>");
tterm = tt - tl;

function time_showed( term )
{
	var d = new Date();
	var milliseconds = d.getTime();
	var this_milli = milliseconds + term;
	var tt = new Date(this_milli);
	var show_time = tt.getFullYear()+'-'+tt.getMonth()+'-'+tt.getDate()+' '+tt.getHours()+':'+tt.getMinutes()+':'+tt.getSeconds();

	$("div[name=time_show_div]").html(show_time);
}

time_showed( tterm );
setInterval( "time_showed( "+tterm+" );", 1000);
</script>

php함수로 서버 시간을 가져온 뒤에 서버와 클라이언트간의 차를 구하고, 그 값만큼을 더한 값으로 시간이 흘러가게 한 것이다.