原生js实现倒计时
来源:互联网 发布:数据库黑客大曝光 编辑:程序博客网 时间:2024/05/22 00:39
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>原生js 当前时间 倒计时代码</title>
<style>
*{margin:0;padding:0;}
body{text-align:center;}
.text{margin-top:150px;font-size:14px;}
</style>
<script>
window.onload=function(){
getMyTime();
getMyTime1();
}
//1.前面补0
function p(n){
return n<10?'0'+n:n;
}
//2.倒计时
function getMyTime(){
var startDate=new Date();
var endDate=new Date('2017/11/14 16:00:00');
var countDown=(endDate.getTime()-startDate.getTime())/1000;
var day=parseInt(countDown/(24*60*60));
var h=parseInt(countDown/(60*60)%24);
var m=parseInt(countDown/60%60);
var s=parseInt(countDown%60);
document.getElementById('time').innerHTML=day+'天'+p(h)+'时'+p(m)+'分'+p(s)+'秒';
setTimeout('getMyTime()',500);
if(countDown<=0){
document.getElementById('time').innerHTML='活动结束';
}
}
//3.当前时间
function getMyTime1(){
var myDate=new Date();
var year=myDate.getFullYear();
var month=myDate.getMonth()+1;
var day=myDate.getDate();
var week=myDate.getDay();
var array=['星期日','星期一','星期二','星期三','星期四','星期五','星期六',];
var hour=myDate.getHours();
var minute=myDate.getMinutes();
var second=myDate.getSeconds();
document.getElementById('time1').innerHTML=year+'年'+month+'月'+day+'日'+' '+array[week]+' '+p(hour)+':'+p(minute)+':'+p(second);
setTimeout('getMyTime1()',500);
}
</script>
</head>
<body>
<div class="text">
<p>倒计时间:<span id="time"></span></p>
<p>当前时间:<span id="time1"></span></p>
</div>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>原生js 当前时间 倒计时代码</title>
<style>
*{margin:0;padding:0;}
body{text-align:center;}
.text{margin-top:150px;font-size:14px;}
</style>
<script>
window.onload=function(){
getMyTime();
getMyTime1();
}
//1.前面补0
function p(n){
return n<10?'0'+n:n;
}
//2.倒计时
function getMyTime(){
var startDate=new Date();
var endDate=new Date('2017/11/14 16:00:00');
var countDown=(endDate.getTime()-startDate.getTime())/1000;
var day=parseInt(countDown/(24*60*60));
var h=parseInt(countDown/(60*60)%24);
var m=parseInt(countDown/60%60);
var s=parseInt(countDown%60);
document.getElementById('time').innerHTML=day+'天'+p(h)+'时'+p(m)+'分'+p(s)+'秒';
setTimeout('getMyTime()',500);
if(countDown<=0){
document.getElementById('time').innerHTML='活动结束';
}
}
//3.当前时间
function getMyTime1(){
var myDate=new Date();
var year=myDate.getFullYear();
var month=myDate.getMonth()+1;
var day=myDate.getDate();
var week=myDate.getDay();
var array=['星期日','星期一','星期二','星期三','星期四','星期五','星期六',];
var hour=myDate.getHours();
var minute=myDate.getMinutes();
var second=myDate.getSeconds();
document.getElementById('time1').innerHTML=year+'年'+month+'月'+day+'日'+' '+array[week]+' '+p(hour)+':'+p(minute)+':'+p(second);
setTimeout('getMyTime1()',500);
}
</script>
</head>
<body>
<div class="text">
<p>倒计时间:<span id="time"></span></p>
<p>当前时间:<span id="time1"></span></p>
</div>
</body>
</html>
阅读全文
0 0
- 原生js实现倒计时
- 原生JS倒计时
- 原生js 页面倒计时
- js原生倒计时
- 原生js倒计时
- js原生-倒计时
- 利用原生Js方法实现发送验证码倒计时
- 用原生js实现距离今年年底倒计时效果
- JS实现倒计时
- js实现倒计时
- js实现考试倒计时
- js实现考试倒计时
- JS实现网站倒计时
- js+php实现倒计时
- JS实现倒计时
- JS 实现时间倒计时
- js实现倒计时
- js实现倒计时功能
- qt creator 内存查看器
- MySql教程____mysql架构体系
- 样式(style)和主题(theme)(一)
- Spring4 之 AOP
- PAT甲级 1049. Counting Ones (30)
- 原生js实现倒计时
- Coursea吴恩达《卷积神经网络》课程笔记(2)深度卷积网络
- [saiku] 将saiku自带的H2嵌入式数据库迁移到本地mysql数据库
- C# 事件记录
- 认识WSGI
- ubuntu12 移植MP3
- 动态规划初步
- Java_HttpClient
- java代码运行Python程序