我在寻找创建动态倒计时的函数时发现了这个问题,我想AJAX是我的解决方案。我修改了在一个网站上找到的一些代码(不记得是哪一个),我将把它发布在这里,希望它对某些人有用。代码如下:
date_default_timezone_set(\'America/Mexico_City\'); //For some reason I needed this to get the number of hours right, it seems like strtotime and time() get different time zones if you don\'t specify a time zone
$nextThursday = strtotime("next Friday, 01:00 PM");
$remaining = $nextThursday - time(); //Calculating the number of seconds between no and the specified future date
$days_remaining = floor($remaining / 86400); //Dividing between the number of seconds in a day to get number of days
$hours_remaining = floor(($remaining % 86400) / 3600); //Getting the number of seconds that didn\'t complete a day and dividing them between the number of seconds in an hour to get the hours remaining
$minutes_remaining = floor((($remaining % 86400) % 3600) / 60);
$seconds_remaining = (($remaining % 86400) % 3600) % 60;
echo "There are $days_remaining days $hours_remaining hours $minutes_remaining minutes left and $seconds_remaining seconds left";