动态显示2019年农历春节倒计时
实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>动态显示2019年农历春节倒计时</title> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <style> *{ background-image: url('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1549352832&di=2602b8e60d1f1e720d753ea9b258b51f&imgtype=jpg&er=1&src=http%3A%2F%2Fimg3.redocn.com%2Ftupian%2F20150130%2Fxuanguangfensehuaduobeijingsucai_3885054.jpg'); background-repeat: no-repeat; background-size: cover; } div{ position: relative; margin-top: 350px; } h1{ text-align: center; } </style> </head> <body> <div> <h1></h1> </div> <script> //入口函数 $(function(){ function Ha(){ var chunjie = Date.parse("Feb 5 2019"); //先获取过年到格林威治时间的秒数 var now = new Date(); var nowtime = now.getTime();//再获取现在到格林威治时间的秒数 var chazhi = Math.floor((chunjie - nowtime)/1000); //取得差值 //计算天数 var tian = Math.floor(chazhi/3600/24); //计算时数 var shi = Math.floor(chazhi%(3600*24)/3600); //计算分数 var fen = Math.floor(chazhi%(3600)/60); //计算秒数 var miao = Math.floor(chazhi%60); $('h1').text("距离过年还有"+tian+"天"+shi+"时"+fen+"分"+miao+"秒"); } setInterval(Ha, 1000); }); </script> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例