有沒有辦法我可以有一個固定的日期,我將用於轉換。固定日期將用於日期轉換
正如你所看到的,下面的代碼表明它是在馬尼拉PH的時間,但是當你打開它,因爲你在不同的時區給我,它會給你不同的時間。日期();只會在你的電腦上得到時間。
有沒有辦法獲得一個日期作爲默認日期,以便我可以添加或減去幾小時來獲得我想要的轉換日期,即使它將在不同的時區打開?
function showTime() {
var a_p = "";
var today = new Date();
var curr_hour = today.getHours();
var curr_minute = today.getMinutes();
var curr_second = today.getSeconds();
\t var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
\t var myDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
\t var date = new Date();
\t var day = date.getDate();
\t var month = date.getMonth();
\t var thisDay = date.getDay(),
\t thisDay = myDays[thisDay];
\t var yy = date.getYear();
\t var year = (yy < 1000) ? yy + 1900 : yy;
if (curr_hour < 12) {
a_p = "<span>AM</span>";
} else {
a_p = "<span>PM</span>";
}
if (curr_hour == 0) {
curr_hour = 12;
}
if (curr_hour > 12) {
curr_hour = curr_hour - 12;
}
curr_hour = checkTime(curr_hour);
curr_minute = checkTime(curr_minute);
curr_second = checkTime(curr_second);
\t document.getElementById('clock-large1').innerHTML=curr_hour + " : " + curr_minute + " : " + curr_second + " " + a_p;
\t document.getElementById('date-large1').innerHTML="<b>" + thisDay + "</b>, " + day + " " + months[month] + " " + year;
}
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
setInterval(showTime, 500);
<div id="clockdate-full">
<div class="wrapper-clockdate1">
<div id="clock-large1"></div>
<div id="date-large1"></div>
<div id="timezone">Manila, PH</div>
</div>
</div>
我建議你可以使用Date.UTC(),我的朋友。請訪問此鏈接參考更多:https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC – Tomato32