} functionshowTime(){ var now=newDate(); var year= now.getFullYear() ; var month= now.getMonth()+1 ; var day= now.getDate() ; var h= now.getHours() ; var m= now.getMinutes() ; var s= now.getSeconds() ; m=checkTime(m) s=checkTime(s)
<!DOCTYPE HTML> <html> <head> <metahttp-equiv="Content-Type"content="text/html; charset=utf-8" /> <title>倒计时时间</title> <linkrel="stylesheet"href="style.css" /> <scriptlanguage="javascript"type="text/javascript"> window.onload = function(){ var timedate= newDate("2017,3,30"); //自定义结束时间 var now = newDate() ; //获取当前时间 var date = timedate.getTime() - now.getTime(); //得出的为毫秒 var time = Math.ceil(date/(1000 * 60 * 60 * 24)) ; //1000 * 60 * 60 * 24一天的秒数 if(time > 0 ){ document.getElementById('timeShow').innerHTML = time; } } </script> </head> <body> <divclass="content2"> <divclass="txtshow">距离设置时间还有<spanid="timeShow"></span>天</div> </div> </body> </html>
使用JavaScript技术,实现团购、限时抢等效果
<!DOCTYPE HTML> <html> <head> <metahttp-equiv="Content-Type"content="text/html; charset=utf-8" /> <title>团购——限时抢</title> <linkrel="stylesheet"href="style.css" /> <script> functionFreshTime() { var end=newDate("2017/5/15,12:20:12");//结束时间 var now = newDate();//当前时间 var lefttime = parseInt((end.getTime()-now.getTime())); var d = parseInt(lefttime/(24*60*60*1000)); var h = parseInt((lefttime/(60*60*60*1000))%24); var m = parseInt(lefttime/(60*1000)%60); var s = parseInt(lefttime/1000%60);