1. <?php
  2. //php的时间是以秒算。js的时间以毫秒算
  3. date_default_timezone_set('PRC');
  4. //date_default_timezone_set("Asia/Hong_Kong");//地区
  5. //配置每天的活动时间段
  6. $starttimestr = "2011-3-29 8:10:00";
  7. $endtimestr = "2011-3-29 9:43:00";
  8. $starttime = strtotime($starttimestr);
  9. $endtime = strtotime($endtimestr);
  10. $nowtime = time();
  11. if ($nowtime<$starttime){
  12. die("活动还没开始,活动时间是:{$starttimestr}至{$endtimestr}");
  13. }
  14. if ($endtime>=$nowtime){
  15. $lefttime = $endtime-$nowtime; //实际剩下的时间(秒)
  16. }else{
  17. $lefttime=0;
  18. die("活动已经结束!");
  19. }
  20. ?>
  21. <script language="JavaScript">
  22. var runtimes = 0;
  23. function GetRTime(){
  24. var nMS = <?php echo$lefttime; ?>*1000-runtimes*1000;
  25. if (nMS>=0){
  26. var nD=Math.floor(nMS/(1000*60*60*24))%24;
  27. var nH=Math.floor(nMS/(1000*60*60))%24;
  28. var nM=Math.floor(nMS/(1000*60)) % 60;
  29. var nS=Math.floor(nMS/1000) % 60;
  30. document.getElementById("RemainD").innerHTML=nD;
  31. document.getElementById("RemainH").innerHTML=nH;
  32. document.getElementById("RemainM").innerHTML=nM;
  33. document.getElementById("RemainS").innerHTML=nS;
  34. if(nMS==5*60*1000)
  35. {
  36. alert("还有最后五分钟!");
  37. }
  38. runtimes++;
  39. setTimeout("GetRTime()",1000);
  40. }
  41. }
  42. window.onload=GetRTime;
  43. </script>
  44. <h4>距离活动结束还有 <strong id="RemainD">XX</strong>天 <strong id="RemainH">XX</strong>小时 <strong id="RemainM">XX</strong>分钟 <strong id="RemainS">XX</strong>秒</h4>
<?php

//php的时间是以秒算。js的时间以毫秒算

date_default_timezone_set('PRC');
//date_default_timezone_set("Asia/Hong_Kong");//地区 //配置每天的活动时间段
$starttimestr = "2011-3-29 8:10:00";
$endtimestr = "2011-3-29 9:43:00"; $starttime = strtotime($starttimestr);
$endtime = strtotime($endtimestr);
$nowtime = time();
if ($nowtime<$starttime){
die("活动还没开始,活动时间是:{$starttimestr}至{$endtimestr}");
}
if ($endtime>=$nowtime){
$lefttime = $endtime-$nowtime; //实际剩下的时间(秒)
}else{
$lefttime=0;
die("活动已经结束!");
}
?> <script language="JavaScript">
var runtimes = 0;
function GetRTime(){
var nMS = <?php echo $lefttime; ?>*1000-runtimes*1000;
if (nMS>=0){
var nD=Math.floor(nMS/(1000*60*60*24))%24;
var nH=Math.floor(nMS/(1000*60*60))%24;
var nM=Math.floor(nMS/(1000*60)) % 60;
var nS=Math.floor(nMS/1000) % 60;
document.getElementById("RemainD").innerHTML=nD;
document.getElementById("RemainH").innerHTML=nH;
document.getElementById("RemainM").innerHTML=nM;
document.getElementById("RemainS").innerHTML=nS;
if(nMS==5*60*1000)
{
alert("还有最后五分钟!");
}
runtimes++;
setTimeout("GetRTime()",1000);
}
}
window.onload=GetRTime;
</script> <h4>距离活动结束还有 <strong id="RemainD">XX</strong>天 <strong id="RemainH">XX</strong>小时 <strong id="RemainM">XX</strong>分钟 <strong id="RemainS">XX</strong>秒</h4>

PHP商品秒杀倒计时的更多相关文章

  1. PHP商品秒杀计时实现(解决大流量方案)

    PHP商品秒杀功能我们多半以整点或时间点为例子,这样对于php来说处理不复杂,但有一个问题就是如果流量大要如何来处理,下面我们一起来看看解决办法. 要求要有小时分钟秒的实时倒计时的显示,用户端修改日期 ...

  2. zookeeper实现商品秒杀抢购

    package com.test; import java.io.IOException; import java.util.List; import java.util.concurrent.Cyc ...

  3. 01 整合IDEA+Maven+SSM框架的高并发的商品秒杀项目之业务分析与DAO层

    作者:nnngu 项目源代码:https://github.com/nnngu/nguSeckill 这是一个整合IDEA+Maven+SSM框架的高并发的商品秒杀项目.我们将分为以下几篇文章来进行详 ...

  4. js 发送短信倒计时、秒杀倒计时实现代码

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...

  5. PHP精确到毫秒秒杀倒计时实例

    精确到毫秒秒杀倒计时PHP源码实例,前台js活动展示倒计时,后台计算倒计时时间.每0.1秒定时刷新活动倒计时时间. PHP: // 注意:php的时间是以秒算.js的时间以毫秒算 // 设置时区 da ...

  6. Java秒杀系统实战系列~商品秒杀代码实战

    摘要: 本篇博文是“Java秒杀系统实战系列文章”的第六篇,本篇博文我们将进入整个秒杀系统核心功能模块的代码开发,即“商品秒杀”功能模块的代码实战. 内容: “商品秒杀”功能模块是建立在“商品详情”功 ...

  7. PHP商品秒杀问题解决方案实例详解【mysql与redis】

    本文实例讲述了PHP商品秒杀问题解决方案.分享给大家供大家参考,具体如下: 引言 假设num是存储在数据库中的字段,保存了被秒杀产品的剩余数量. if($num > 0){ //用户抢购成功,记 ...

  8. 03 整合IDEA+Maven+SSM框架的高并发的商品秒杀项目之web层

    Github:https://github.com/nnngu 项目源代码:https://github.com/nnngu/nguSeckill 前端交互流程设计 对于一个系统,需要产品经理.前端工 ...

  9. 02 整合IDEA+Maven+SSM框架的高并发的商品秒杀项目之Service层

    作者:nnngu 项目源代码:https://github.com/nnngu/nguSeckill 首先在编写Service层代码前,我们应该首先要知道这一层到底是干什么的. Service层主要负 ...

随机推荐

  1. css3 transition属性变化与animation动画的相似性以及不同点

    下面列子中的2个图片的效果. http://zqtest.e-horse.cn/DongXueImportedCar/assets/mouseOverAnimate.html 第一个为transiti ...

  2. ligerui多选动态下拉框

    今天下午要求做一个支持多选的,并且插件用ligerui的,当时有点小懵了,因为没用过ligerui啊!而且按照API的介绍,我做得也很好啊,可是为什么就是显示不出来?据说有位小神比较厉害,请教来之,两 ...

  3. Internal Server Error500

    开启#LoadModule rewrite_module modules/mod_rewrite.so

  4. http://www.cnblogs.com/peida/archive/2013/04/23/3036035.html

    http://www.cnblogs.com/peida/archive/2013/04/23/3036035.html

  5. UIImage 调整图片大小

    -(UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size { UIGraphicsBeginImageContext(size); [img d ...

  6. Shell数组的增删改查

    Shell数组的增删改查 shell数组的定义及取值: a=(1 2 3) [root@bogon tmp]# echo ${a[*]}  1 2 3 [root@bogon tmp]# echo $ ...

  7. Tomcat启动时自动加载一个类

    有时候在开发Web应用的时候,需要tomcat启动后自动加载一个用户的类,执行一些初始化方法,如从数据库中加载业务字典到内存中,因此需要在tomcat启动时就自动加载一个类,或运行一个类的方法. 可以 ...

  8. Android --资料集合

    google android 官方教程 http://hukai.me/android-training-course-in-chinese/basics/index.html android视频资料 ...

  9. dom core,html dom,css dom,jquery 中的dom操作

    前端开发中为达到某种目的,往往有很多方法:dom core,html dom,jquery; dom core/jquery主要通过函数调用的方式(getAttribute("属性名&quo ...

  10. 【关于HBITMAP, DC, MEM DC, Clipboard】将HBITMAP拷贝到Clipboard(Windows Clipboard & OLE Clipboard)

    参考: Programming Windows with MFC, 2nd. Chapter 18, 19. 建议把这两章学习完(至少到OLE drag-and-drop之前要学习完)再来尝试OLE ...