2015-01-15 4 views
-1

this site의 jQuery 시계 코드를 사용하고 있으며 시계가 항상 동부 표준시 (GMT-5)로 표시되는 것을 제외하고 모든 것이 잘 작동합니다. 이를 반영하기 위해이 코드를 어떻게 편집합니까?jQuery 시계 코드

jQuery를 스크립트 :

$(document).ready(function() { 
// Create two variable with the names of the months and days in an array 
var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; 
var dayNames= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"] 

// Create a newDate() object 
var newDate = new Date(); 
// Extract the current date from Date object 
newDate.setDate(newDate.getDate()); 
// Output the day, date, month and year  
$('#Date').html(dayNames[newDate.getDay()] + " " + newDate.getDate() + ' ' + monthNames[newDate.getMonth()] + ' ' + newDate.getFullYear()); 

setInterval(function() { 
    // Create a newDate() object and extract the seconds of the current time on the visitor's 
    var seconds = new Date().getSeconds(); 
    // Add a leading zero to seconds value 
    $("#sec").html((seconds < 10 ? "0" : "") + seconds); 
    },1000); 

setInterval(function() { 
    // Create a newDate() object and extract the minutes of the current time on the visitor's 
    var minutes = new Date().getMinutes(); 
    // Add a leading zero to the minutes value 
    $("#min").html((minutes < 10 ? "0" : "") + minutes); 
    },1000); 

setInterval(function() { 
    // Create a newDate() object and extract the hours of the current time on the visitor's 
    var hours = new Date().getHours(); 
    // Add a leading zero to the hours value 
    $("#hours").html((hours < 10 ? "0" : "") + hours); 
    }, 1000); 

}); 

HTML 코드 : 나는 Exchange가 전문가의 라이너 Jeschor에서 답을받을 수 있었다

<div class="container"> 
<div class="clock"> 
<div id="Date"></div> 

<ul class="clock-ul"> 
    <li class="clock-li" id="hours"> </li> 
    <li class="clock-li" id="point">:</li> 
    <li class="clock-li" id="min"> </li> 
    <li class="clock-li" id="point">:</li> 
    <li class="clock-li" id="sec"> </li> 
</ul> 

</div> 
</div> 
+0

이 질문은 그것이 내가이 기본적으로 [이 질문의 중복 (http://stackoverflow.com 생각 –

+0

를 EE하지 HTML 및 JQUERY에 대해 때문에 오프 주제로 표시됩니다 : 당신은 여기에 바이올린을 볼 수 있습니다/questions/10087819/convert-date-to-another-timezone-in-javascript) –

+0

[이 질문에] (http://stackoverflow.com/questions/439630/how-do-you-create-a-javascript-date -object-with-a-set-time-without-using-as)는 가능한 몇 가지 해결책을 나열합니다. – chrki

답변

0

. http://jsfiddle.net/EE_RainerJ/umcka2th/

setInterval(function() { 
// Define the tomezones offset 
var timezoneOffset = -5; 
// Get the local date from client 
var currentDate = new Date(); 
// Get UTC time 
utcDate = currentDate.getTime() + (currentDate.getTimezoneOffset() * 60000); 
// Set to UTC - 5 
estDate = new Date(utcDate + (3600000*timezoneOffset)); 
var seconds = estDate.getSeconds(); 
var minutes = estDate.getMinutes(); 
var hours = estDate.getHours(); 

// Add a leading zero to seconds value 
$("#sec").html((seconds < 10 ? "0" : "") + seconds); 
// Add a leading zero to the minutes value 
$("#min").html((minutes < 10 ? "0" : "") + minutes); 
// Add a leading zero to the hours value 
$("#hours").html((hours < 10 ? "0" : "") + hours); 
},1000);