enter image description here
基本上我用SQL查詢插入一個帶有日期時間間隔(將來的東西)的行。Javascript倒計時和時區
$interval = new DateInterval('PT'.$H.'H'.$i.'M'.$s.'S');
$date = new DateTime(); $date->add($interval);
$query = $conn->prepare("INSERT INTO profiles_in_missions (id_pim, id_profile, id_mission, time) VALUES (NULL, :idprofile, :idmission,:time)");
$query->bindValue(':idprofile', $tableau[0]);
$query->bindValue(':idmission', $id);
$query->bindValue(':time', $date->format('Y-m-d H:i:s'));
$query->execute();
如果我的電腦顯示:23:40,如果我用的+8分鐘間隔插入日期時間,這個查詢將存儲21:48在數據庫中。到現在爲止,我的數據庫是GTM + 00,我的電腦默認瀏覽器是GTM + 2。
一旦存儲,我想挑選這個日期誰得到(在這種情況下)-2小時+ 8米,並作出倒計時。
現在的問題:爲了讓倒計時,我使用JavaScript和我做21:48 - 現在();但他總是會比平時快2小時,因爲存儲日期(21:48)在MYSQL中用GTM + 00 BUT Javascript now();正在獲取我的默認瀏覽器時間GTM + 2。
有沒有辦法使Javascript與服務器Timezone GTM + 00一起使用?我如何解決我的問題?還有就是我的倒計時所有代碼:
<script>
var t = document.getElementById('myInputTimer').value;
var countDownDate = new Date(t).getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now an the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var hours = Math.floor((distance % (1000 * 60 * 60 * 24))/(1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60))/(1000 * 60));
var seconds = Math.floor((distance % (1000 * 60))/1000);
// Display the result in the element with id="demo"
document.getElementById("demo").innerHTML = hours + "h "
+ minutes + "m " + seconds + "s ";
// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "EXPIRED";
}
}, 1000);
</script>
**我現在只想吻你!**非常感謝你。非常感謝您花時間陪伴您。他工作100% –