[英]PHP/JQuery/JavaScript Countdown
I'm trying to use the jQuery Countdown (http://code.google.com/p/jquery-countdown/) to display a countdown to a specific date and time, but you need to program the number of days, hours, minutes, and seconds into the jQuery call. 我正在尝试使用jQuery Countdown(http://code.google.com/p/jquery-countdown/)来显示特定日期和时间的倒数,但是您需要对天数,小时数,分钟和几秒钟进入jQuery调用。
I'm not quite sure how to do this in JS, but I figured using PHP to calculate the time and then having it plug those variables in would work. 我不太确定如何在JS中执行此操作,但是我认为使用PHP计算时间,然后将其插入这些变量中即可。 I found this PHP function online, but I'm unsure of the math to add a $seconds_left.
我在网上找到了这个PHP函数,但是我不确定添加$ seconds_left的数学方法。 Could someone please help?
有人可以帮忙吗?
function countdown($year, $month, $day, $hour, $minute)
{
// make a unix timestamp for the given date
$the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);
// get current unix timestamp
$today = time();
$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;
global $days_left;
global $hours_left;
global $minutes_left;
$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
}
Thanks! 谢谢!
You should be able to get seconds left by: 您应该能够通过以下方式获得秒数:
$seconds_left = floor($difference - $days_left*60*60*24 - $hours_left*60*60 - $minutes_left*60);
That should get you the seconds you're looking for (assuming the rest of the code works correctly, I'll admit I haven't tested this). 那应该可以让您快速找到所需的秒数(假设其余代码正常工作,我承认我尚未测试过)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.