jQuery+PHP动态显示(项目)实时时间和倒计时
jQuery动态显示当前时间:
html代码:<div id="current_time"></div>
setInterval()使用:setInterval(functionName,timeOut);
setInterval使用示例:
jQuery代码:
<script type="text/javascript">
setInterval(function() {
var now = (new Date()).toLocaleString();
$('#current-time').text(now);
}, 1000);
</script>
整合示例教程-->jQuery+PHP动态显示项目倒计时:
html代码:
<ul class="public-time-left">
<li><p id="time_d"></p><span>天</span></li>
<li><p id="time_h"></p><span>小时</span></li>
<li><p id="time_m"></p><span>分</span></li>
<li><p id="time_s"></p><span>秒</span></li>
</ul>
PHP代码: //以TP框架为例,将php后台数据【项目截止时间】传到前端
$this->assign("endtime",$end_time); //不是时间戳,是格式化后的时间,方便js计算
jQuery代码:
//比如写在一个.js文件里,在html页面引入即可。
/*倒计时*/
function GetRTime(){
var voere=voertime;
//不是时间戳,是格式化后的时间,方便js计算
var EndTime= new Date(voere); var NowTime = new Date(); var t =EndTime.getTime() - NowTime.getTime(); var d=0; var h=0; var m=0; var s=0; if(t>=0){ d=Math.floor(t/1000/60/60/24); h=Math.floor(t/1000/60/60%24); m=Math.floor(t/1000/60%60); s=Math.floor(t/1000%60); } document.getElementById("time_d").innerHTML = d ; document.getElementById("time_h").innerHTML = h ; document.getElementById("time_m").innerHTML = m ; document.getElementById("time_s").innerHTML = s ; }
最后一步:在html页面的脚本里调用引入js的GetRTime方法
/* setInterval()很重要:作用是每隔一定时间就调用函数,方法或对象。 */
<script type="text/javascript">var voertime = '{$deal_info.over_time}'; //php的截止时间,不是时间戳,是格式化后的时间,方便js计算
{if ($deal_info.end_time > $now or $deal_info.end_time eq 0) and $deal_info.begin_time < $now and $deal_info.is_effect eq 1 } setInterval(GetRTime,0); {/if} </script>
jQuery+PHP动态显示(项目)实时时间和倒计时的更多相关文章
- 微信小程序+PHP:动态显示项目倒计时(格式:4天7小时58分钟39秒)
1.一般我们说的显示秒杀都是指的单条数据,循环我没做. 效果: 2.wxml代码: <p class="endtime_act">距报名截止还有: <block ...
- [Jquery 插件]活动倒计时,可同步服务器时间,倒计时格式随意设置
活动倒计时,可同步服务器时间,倒计时格式随意设置 使用说明 /* #活动倒计时,可同步服务器时间 startTime:起始时间 endTime:结束时间 format_str:字符模板 speed:倒 ...
- 为jQuery的$.ajax设置超时时间
jQuery的ajax模块封装了非常强大的功能,有时候我们在发送一个ajax请求的时候希望能有一个超时的时间,想让程序在一段时间请求不到数据时做出一些反馈.幸运的是jQuery为我们提供了这样的参数: ...
- Mysql查找所有项目开始时间比之前项目结束时间小的项目ID
这是之前遇到过的一道sql面试题,供参考学习: 查找所有项目开始时间比之前项目结束时间小的项目ID mysql> select * from t2; +----+---------------- ...
- JS 显示时间与倒计时练习
显示时间与倒计时 HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...
- HTML 动态显示系统当前时间
HTML 动态显示系统当前时间: <div id="time"> <script> document.getElementById('time').inne ...
- Unity日常记录-本地保存未来时间实现倒计时
本地保存未来时间实现倒计时 TimeTool工具类:获取当前时间.未来时间.两时间差 using System; using UnityEngine; public class TimeTool { ...
- vue.js实战——vue 实时时间
created:实例创建完成后调用,此阶段完成了数据的观测等,但尚未挂载,$el还不可用,需要初始化处理一些数据时会比较有用. mounted:el挂载到实例上后调用,一般我们的第一个业务逻辑会在这里 ...
- Vue的实时时间转换Demo
Vue的实时时间转换Demo time.html: <!DOCTYPE html> <html lang="en"> <head> <me ...
随机推荐
- 基于Java IO 序列化方案的memcached-session-manager多memcached节点配置
在公司项目里想要在前端通过nginx将请求负载均衡,而后台的几组tomcat的session通过memcached(non-sticky模式)进行统一管理,这几组tomcat部署的web app是同一 ...
- python异常信息获取
1.python调试的时候获取异常信息 import traceback print '######################################################## ...
- [转]Unicode和UTF-8的关系
Unicode和UTF-8的关系作者: 张军 原文地址: http://blog.renren.com/blog/284133452/485453790 今天中午,我突然想搞清楚Unicode和UTF ...
- linux C 多线程/线程池编程 同步实例
在多线程.线程池编程中经常会遇到同步的问题. 1.创建线程 函数原型:int pthread_create(pthread_t *thread, const pthread_attr_t *attr, ...
- WebApi的缺点
post只能传递对象 必须要参数一致,不能同名称
- 【转】Understanding the Angular Boot Process
原文: https://medium.com/@coderonfleek/understanding-the-angular-boot-process-9a338b06248c ----------- ...
- 主成分分析(PCA)
相对与网上很多人分享的有关PCA的经历,我第一次接触PCA却不是从人脸表情识别开始的,但我所在的实验室方向之一是人脸的研究,最后也会回到这个方向上来吧. PCA(principal component ...
- GetProcAddress 使用注意事项
使用 GetProcAddress Function 时,有以下几点需要特别留意: 1. 第二个参数类型是 LPCSTR,不是 : 2. 用 __declspec(dllexport),按 C 名称修 ...
- [Algorithm] Serialize and Deserialize Binary Tree
Given the root to a binary tree, implement serialize(root), which serializes the tree into a string, ...
- oracle client字符集设置 乱码问题
程序员经常要连接数据库 下面 就说一下 oracle数据库 客户端与服务器端 字符集一致性的问题 这可以解决中文乱码,其他字符乱码问题 主要是指在sqlplus中,其他类似toad/pls ...