jquery 显示*天*时*分*秒实现时间计时器 - Web前端
作者:98wpeu发布时间:2026-08-07分类:网页前端技术浏览:2
导读:1.用JQuery实现时间计时器,从之前的某个时间段到现在距离多少天多少时多少分多少秒?html代码:复制代码代码如下:<divid="times_wrap"cla...
1.用JQuery实现时间计时器,从之前的某个时间段到现在距离多少天多少时多少分多少秒?
html代码:
复制代码 代码如下:
<div id="times_wrap" class="time_num">
距离现在时间:
<div class="time_w">
<span id="time_d" class="time"> </span >天
<span id="time_h" class="time"> </span >时
<span id="time_m" class="time"> </span >分
<span id="time_s" class="time"> </span >秒
</div>
</div>
<scripttype="text/javascript">
$(function(){
show_time();
});
function show_time(){
var time_start = new date("2013/10/01 00:00:00").getTime();//设定开始时间
var time_end = new date().getTime(); //设定结束时间(等于系统当前时间)
//计算时间差
var time_distance = time_end - time_start;
if(time_distance > 0){
// 天时分秒换算
var int_day = Math.floor(time_distance/86400000)
time_distance -= int_day * 86400000;
var int_hour = Math.floor(time_distance/3600000)
time_distance -= int_hour * 3600000;
var int_minute = Math.floor(time_distance/60000)
time_distance -= int_minute * 60000;
var int_second = Math.floor(time_distance/1000)
// 时分秒为单数时、前面加零
if(int_day < 10){
int_day = "0" + int_day;
}
if(int_hour < 10){
int_hour = "0" + int_hour;
}
if(int_minute < 10){
int_minute = "0" + int_minute;
}
if(int_second < 10){
int_second = "0" + int_second;
}
// 显示时间
$("#time_d").HTML(int_day);
$("#time_h").html(int_hour);
$("#time_m").html(int_minute);
$("#time_s").html(int_second);
setTimeout("show_time()",1000);
}else{
$("#time_d").html('00');
$("#time_h").html('00');
$("#time_m").html('00');
$("#time_s").html('00');
}
}
</script>
html代码:
复制代码 代码如下:
<div id="times_wrap" class="time_num">
距离现在时间:
<div class="time_w">
<span id="time_d" class="time"> </span >天
<span id="time_h" class="time"> </span >时
<span id="time_m" class="time"> </span >分
<span id="time_s" class="time"> </span >秒
</div>
</div>
<scripttype="text/javascript">
$(function(){
show_time();
});
function show_time(){
var time_start = new date("2013/10/01 00:00:00").getTime();//设定开始时间
var time_end = new date().getTime(); //设定结束时间(等于系统当前时间)
//计算时间差
var time_distance = time_end - time_start;
if(time_distance > 0){
// 天时分秒换算
var int_day = Math.floor(time_distance/86400000)
time_distance -= int_day * 86400000;
var int_hour = Math.floor(time_distance/3600000)
time_distance -= int_hour * 3600000;
var int_minute = Math.floor(time_distance/60000)
time_distance -= int_minute * 60000;
var int_second = Math.floor(time_distance/1000)
// 时分秒为单数时、前面加零
if(int_day < 10){
int_day = "0" + int_day;
}
if(int_hour < 10){
int_hour = "0" + int_hour;
}
if(int_minute < 10){
int_minute = "0" + int_minute;
}
if(int_second < 10){
int_second = "0" + int_second;
}
// 显示时间
$("#time_d").HTML(int_day);
$("#time_h").html(int_hour);
$("#time_m").html(int_minute);
$("#time_s").html(int_second);
setTimeout("show_time()",1000);
}else{
$("#time_d").html('00');
$("#time_h").html('00');
$("#time_m").html('00');
$("#time_s").html('00');
}
}
</script>
相关推荐
- 对之前写的jquery分页做下升级 - Web前端
- jQuery 鼠标经过(hover)事件的延时处理示例 - Web前端
- jquery中的ajax方法怎样通过JSONP进行远程调用 - Web前端
- JQuery动画animate的stop方法使用详解 - Web前端
- 在jquery中combobox多选的不兼容问题总结 - Web前端
- jQuery如何将选中的对象转化为原始的DOM对象 - Web前端
- jQuery避免$符和其他JS库冲突的方法对比 - Web前端
- jquery查找父元素、子元素(个人经验总结) - Web前端
- jquery中$.post()方法的简单实例 - Web前端
- jquery数组之存放checkbox全选值示例代码 - Web前端
- 网页前端技术排行
-
- 1[Web前端]用javascript实现默认图片替代未显示的图片 - Web前端
- 2分析Iconfont-阿里巴巴矢量常用图标库 - Web前端
- 3jQuery实例教程:制作网页中可折叠的面板 - Web前端
- 4【第六章】Foundation之按钮和下拉功能 - Web前端
- 5基于jquery的滚动条滚动固定div(附演示下载) - Web前端
- 6jQuery编写widget的一些技巧分享 - Web前端
- 7分享精心挑选的12款优秀jQuery Ajax分页插件和教程 - Web前端
- 8jQuery实现鼠标移到元素上动态提示消息框效果 - Web前端
- 9在Mac/PC上远程调试iPhone/iPad上的网页 - Web前端
- 最近发表
-
- WordPress随机显示特色图片插件:Random Post Thumbnails
- KeePass实现Chrome浏览器自动填充密码方法一
- LNMP一键包nginx 301强制跳转到https教程
- KeePass实现Chrome浏览器自动填充密码方法二
- #建站# 免费的VPS管理软件Xshell8/Xftp8中文版下载
- 使用Xshell 8连接VPS教程_电脑登录vps的方法
- WordPress评论界面添加烟花????效果
- 不同浏览器书签同步方案:坚果云+Floccus_详细使用教程
- iOS端KeePassXC客户端APP:Strongbox Password Safe
- 给WordPress评论中的Gravatar头像图片添加ALT属性


