![](/img/trans.png)
[英]Displaying a synchronized countdown timer with server side automatic time logout?
[英]Timer, timezone, server side time, client side countdown
我最近(在這里)啟動了一個項目,但遇到了計時器/時間問題:
我有一個cronjob,每天運行兩次,每天兩次:在法國時區的午夜和正午。
我想顯示“倒數至下一頁”,實際上是倒數至cronjob。
我有點困惑,因為當我開始思考與時區和時區相關的事情時,我的大腦就凍結了。
我知道我應該占用服務器端時間,並在客戶端計時器中顯示我的變量(而無需獲取客戶端時間),但僅此而已。
我真的很感謝一些建議!
在此先感謝大家!
您可以為此使用php DateTime
。
這是一個例子。
$now = new DateTime;
$morning = new DateTime('08:00');
$night = new DateTime('22:00');
// next time is night
if( $now > $morning && $now < $night )
{
$time = $now->diff($night);
}
// next time is day
else
{
$time = $now->diff($morning);
}
$target = $time->format('%h:%i:%s'); // returns a string.
您應該使用Keith Wood的倒數計時器: http : //keith-wood.name/countdown.html
它非常易於使用。
您要做的就是
$('#timer').countdown({
until: '<?php echo date("h:i:s"); ?>' // change this, obviously
});
這是小提琴: http : //jsfiddle.net/tqyj4/289/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.