서버시간기준 다른나라시계 소스

아래 예제는 캐나다 토론토시간 입니다
시계표시 부분만 자바스크립트입니다.
php로 저장하시고 iframe 으로 불러서 사용하세요.
시간은 리플레쉬되나, 날짜가 변경될때는 리플레쉬가 이루어지지 않아 10분 단위로 리플레쉬되게 했습니다.

<?
$subt_time="14" ;// 원하는 나라와 시간차
$summ_time="" ;// 섬머타임 시즌일 경우 시간차(수동)
$relat_time="-" ;// 한국시간 기준으로 늦으면 -, 빠르면 + 입력
if ($summ_time) {
 $tflag=$summ_time;
 $sflag="+ '[썸머타임]'";
}
else $tflag=$subt_time;
?>
<head>
<meta http-equiv="refresh" content="600; url=watch.php">
<style type=text/css>
body, td { font-family:Tahoma,굴림; font-size:9pt; color:#222222; }
</style>
</head>

<body leftmargin="0" topmargin="0" >
<center>
<table width="166" cellspacing="0" cellpadding="0" border="0">
<tr>
 <td background="http://alpha12.namoweb.net/sjh/sjh/img/bg_line_01.gif" width="6" height="6"></td>
 <td background="http://alpha12.namoweb.net/sjh/sjh/img/bg_line_02.gif" width="1" height="6"></td>
 <td background="http://alpha12.namoweb.net/sjh/sjh/img/bg_line_03.gif" width="6" height="6"></td>
</tr>
<tr>
 <td background="http://alpha12.namoweb.net/sjh/sjh/img/bg_line_l.gif" width="6" height="6"></td>
 <td background="http://alpha12.namoweb.net/sjh/sjh/img/watch.jpg">
<center>
<font color=#F77111><b>K</b>OREA</font>
<?
$stamp = mktime();
$str = date("a", $stamp);
$days = array("일","월","화","수","목","금","토");
$temp_day = date("w", strtotime("$time"));  // 요일을 0,1,2~로 구함
$mmdd = date("n월 j일", $stamp);
if ($str == "am"){
$morning = "<font color=blue><b>오전</b></font>";}
else {
$morning = "<font color=red><b>오후</b></font>";}
echo "(".$days[$temp_day].") <br>".$mmdd." ".$morning;
?>
<div id=divTime></div>
<div style="font-size: 1px; line-height: 0; height: 3px;"> </div>

<font color=#F77111><b>T</b>ORONTO</font>
<?
if ($relat_time=="-"){
$stamp = mktime() - 60*60*$tflag ;
$temp_day = date("w", strtotime("-$tflag hours")); 
}
else {
$stamp = mktime() + 60*60*$tflag ;
$temp_day = date("w", strtotime("+$tflag hours")); 
}
$str = date("a", $stamp);
$days = array("일","월","화","수","목","금","토");

$mmdd = date("n월 j일", $stamp);
if ($str == "am"){
$morning = "<font color=blue><b>오전</b></font>";}
else {
$morning = "<font color=red><b>오후</b></font>";}
echo "(".$days[$temp_day].") <br>".$mmdd." ".$morning;
?>
<div id=divTime2></div>
</center>
</td>
 <td background="http://alpha12.namoweb.net/sjh/sjh/img/bg_line_r.gif" width="6" height="6"></td>
</tr>
<tr>
 <td background="http://alpha12.namoweb.net/sjh/sjh/img/bg_line_04.gif" width="6" height="6"></td>
 <td background="http://alpha12.namoweb.net/sjh/sjh/img/bg_line_05.gif" width="1" height="6"></td>
 <td background="http://alpha12.namoweb.net/sjh/sjh/img/bg_line_06.gif" width="6" height="6"></td>
</tr>
</table>
</center>

<SCRIPT LANGUAGE="JAVASCRIPT">
<!--
function show2(i) {
if ( !i ) { i = 0; }
today = new Date()
var relat_time = '<?=$relat_time?>';
var nnn = today.getTime();
var time_value = <?echo mktime();?> * 1000 + i;

if ( relat_time == '-' )
var toronto_value = ( <?echo mktime();?>- 60*60*<?=$tflag?> )* 1000 + i;
else
var toronto_value = ( <?echo mktime();?>+ 60*60*<?=$tflag?> )* 1000 + i;

var now = new Date();
var now2 = new Date();
// 한국시간 추출
now.setTime(time_value);
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
// 토론토 시간 추출
now2.setTime(toronto_value);
var h = now2.getHours();
var m = now2.getMinutes();
var s = now2.getSeconds();

if ( hours > 12 ) hours = hours - 12;
if ( hours == 0 ) hours = 12;
if ( minutes <= 9 ) minutes = "0" + minutes;
if ( seconds <= 9 ) seconds = "0" + seconds;

if ( h > 12 ) h = h - 12;
if ( h == 0 ) h = 12;
if ( m <= 9 ) m = "0" + m;
if ( s <= 9 ) s = "0" + s;

var ctime = hours + ":" + minutes + ":" + seconds;
var ttime = h + ":" + m + ":" + s <?=$sflag?>;

document.all.divTime.innerHTML = ctime ;
document.all.divTime2.innerHTML = ttime ;
i = i + 1000;
setTimeout ("show2("+i+")", 1000);
}
show2();

//-->
</SCRIPT>
</body>

|

댓글 4개

자바스크립트 특성상 클라이언트 프로그램이어서 그런지 내 컴퓨터의 타임존을 변경하면
시계가 이상하게 나오네요..

예를들어 타임존을 서울이나 또는 미국 다른 나라로 했을 경우 말입니다.
위 소스대로 하셨는데 그렇단 말씀이죠?
이상하네요.. 로컬피씨의 시간정보와는 무관한데..
서버타임을 받아 자스로 디스플레이한건데..
혹시 링크된 시계도 피씨 시간에 영향을 받는지 확인해 보세요..
좋은 팁이네요 감사
늦게나마 좋은 팁 감사합니다.
댓글을 작성하시려면 로그인이 필요합니다. 로그인

그누4 팁자료실

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요. 나누면 즐거움이 커집니다.

+
제목 글쓴이 날짜 조회
17년 전 조회 5,364
17년 전 조회 3,333
17년 전 조회 1만
17년 전 조회 7,031
17년 전 조회 3,969
17년 전 조회 5,548
17년 전 조회 3,447
17년 전 조회 4,474
17년 전 조회 1.3만
17년 전 조회 4,655
17년 전 조회 3,277
17년 전 조회 5,239
17년 전 조회 2,885
17년 전 조회 3,284
17년 전 조회 3,118
17년 전 조회 6,698
17년 전 조회 3,360
17년 전 조회 8,250
17년 전 조회 7,731
17년 전 조회 4,194
🐛 버그신고