-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代碼:
<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>
這個問題似乎是題外話,因爲它是關於HTML和jQuery的不EE –
我認爲這基本上是一個[這個問題的重複(http://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript) –
[This question](http://stackoverflow.com/questions/439630/how-do-you-create-a-javascript-date -object-with-a-set-timezone-without-using-as)也列出了一些可能的解決方案。 – chrki