zoukankan      html  css  js  c++  java
  • js算出此时此刻的时间和距离某一天的时间

    <!DOCTYPE html>
    <html lang="en">
    	<head>
    		<meta charset="utf-8">
    		<title>Swiper demo</title>
    		<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
    
    		<!-- Demo styles -->
    		<style>
    			div.clock {
    				text-align: center;
    				font-size: 30px;
    			}
    
    			div.clock>span {
    				padding: 6px;
    				background-color: skyblue;
    			}
    
    			.title {
    				 430px;
    				height: 45px;
    				margin: 200px auto 50px;
    			}
    
    			.title-item strong {
    				background-color: orange;
    				color: #fff;
    				font-size: 36px;
    				padding: 0 10px;
    				border-radius: 5px;
    				box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
    				font-family: Arial, Helvetica, sans-serif;
    				margin-right: 10px;
    				line-height: 49px;
    			}
    
    			.title-item {
    				 430px;
    				height: 45px;
    				margin: 0 auto;
    			}
    
    			.title-item>span {
    				line-height: 49px;
    				font-size: 32px;
    				color: orange;
    			}
    			.clock span{color:red;}
    		</style>
    	</head>
    	<body>
    		 <div class="clock">
    			  <span id="d"></span>:
    		    <span id="h"></span>:
    		    <span id="m"></span>:
    		    <span id="s"></span>
    		</div>
    		<h1 class="title">距离国庆节10月1号,还有</h1>
    		<div class="title-item">
    		    <span><span id="days"></span>天</span>
    		    <strong><span id="hours"></span>时</strong>
    		    <strong><span id="minutes"></span>分</strong>
    		    <strong><span id="seconds"></span>秒</strong>
    		</div>
    
    		<script src="swiper4/jquery.min.js"></script>
    		<script>
    			function getCurrentTime(){
    				var date=new Date();
    				var ds=toTwo(date.getDate());
    				var hs=toTwo(date.getHours());
    				var ms=toTwo(date.getMinutes());
    				var ss=toTwo(date.getSeconds());
    				$('#d').html(ds);
    				$('#h').html(hs);
    				$('#m').html(ms);
    				$('#s').html(ss);
    			}
    			function toTwo(val){
    				return val<10?'0'+val:val
    			}
    			getCurrentTime()
    			setInterval(getCurrentTime, 1000);
    			// 倒计时 距离国庆节10月1日还有多少天多少时多少分多少秒
    			var endTime = new Date("2019-10-01 0:0:0");
    			setInterval(getDjs,1000);
    			function getDjs(){
    				var now=new Date();
    				var diff=endTime.getTime()-now.getTime();
    				diff=diff/1000;
    				var day,hour,minute,seconds;
    				day=Math.floor(diff/(24*60*60));
    				hour=Math.floor((diff/(60*60))%24);
    				minute=Math.floor(diff/60%24);
    				seconds=Math.floor(diff%60);
    				$('#days').html(toTwo(day));
    				$('#hours').html(toTwo(hour));
    				$('#minutes').html(toTwo(minute));
    				$('#seconds').html(toTwo(seconds));
    			}
    			getDjs();
    			
    		</script>
    	</body>
    </html>
    
    
  • 相关阅读:
    php header
    How to Share a Theme With All Users in a Windows 7 Computer?
    240多个jQuery插件
    Delphi读写UTF8、Unicode格式文本文件
    虚拟网关解决ARP批处理版
    从煎蛋网上抓取妹子图
    在【批处理】中过滤特殊字符
    反序列化(临时)
    python发邮件实例
    反序列化(临时)
  • 原文地址:https://www.cnblogs.com/lxystar/p/11187745.html
Copyright © 2011-2022 走看看