Home > php教程 > PHP源码 > php实时倒计时

php实时倒计时

PHP中文网
Release: 2016-05-25 17:14:59
Original
1242 people have browsed it

实例:
/**************************************
**功能:PHP实时倒计时
**创建日期:2009-2-26
**作者:潘继强
**
***************************************/
//php的时间是以秒算。js的时间以毫秒算
date_default_timezone_set("Asia/Hong_Kong");//地区
//配置每天的活动时间段
$starttimestr = "09:00:00";
$endtimestr = "18:30:00";
$starttime = strtotime($starttimestr);
$endtime = strtotime($endtimestr);
$nowtime = time();
?>

实例2:
修改了上面的一些bug
/**************************************
**功能:PHP实时倒计时
**创建日期:2009-2-26
**作者:潘继强
**
***************************************/
//php的时间是以秒算。js的时间以毫秒算

date_default_timezone_set("Asia/Hong_Kong");//地区

//配置每天的活动时间段
$starttimestr = "09:00:00";
$endtimestr = "18:30:00";
$starttime = strtotime($starttimestr);
$endtime = strtotime($endtimestr);
$nowtime = time();
?>
实例3:
思路不同,简单多了.
/**************************************
**功能:PHP实时倒计时
**创建日期:2009-2-26
**作者:潘继强
**
***************************************/
//php的时间是以秒算。js的时间以毫秒算

date_default_timezone_set("Asia/Hong_Kong");//地区

//配置每天的活动时间段
$starttimestr = "09:00:00";
$endtimestr = "13:50:00";

$starttime = strtotime($starttimestr);
$endtime = strtotime($endtimestr);
$nowtime = time();
if ($nowtime<$starttime){
die("活动还没开始,活动时间是:{$starttimestr}至{$endtimestr}");
}
$lefttime = $endtime-$nowtime; //实际剩下的时间(秒)
?>

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template