我是靠谱客的博主 殷勤未来,最近开发中收集的这篇文章主要介绍HTML当前日期和倒计时展示1、展示当前日期:2、倒计时时间展示,以双十一倒计时为例:,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1、展示当前日期:

代码如下:转载自:http://blog.csdn.net/a13432421434/article/details/70173250

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>show_time</title>
</head>
<body>
<div id="main">
<div id="show_time">
<script>
setInterval("show_time.innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);
</script>
</div>
</div>
</body>
</html>
或者:转载自: http://blog.csdn.net/mr_gly_di/article/details/53668592

<html>
<head>
<SCRIPT language=JavaScript>
function tick() {
var years,months,days,hours, minutes, seconds;
var intYears,intMonths,intDays,intHours, intMinutes, intSeconds;
var today;
today = new Date(); //系统当前时间
intYears = today.getFullYear(); //得到年份,getFullYear()比getYear()更普适
intMonths = today.getMonth() + 1; //得到月份,要加1
intDays = today.getDate(); //得到日期
intHours = today.getHours(); //得到小时
intMinutes = today.getMinutes(); //得到分钟
intSeconds = today.getSeconds(); //得到秒钟
years = intYears + "-";
if(intMonths < 10 ){
months = "0" + intMonths +"-";
} else {
months = intMonths +"-";
}
if(intDays < 10 ){
days = "0" + intDays +" ";
} else {
days = intDays + " ";
}
if (intHours == 0) {
hours = "00:";
} else if (intHours < 10) {
hours = "0" + intHours+":";
} else {
hours = intHours + ":";
}
if (intMinutes < 10) {
minutes = "0"+intMinutes+":";
} else {
minutes = intMinutes+":";
}
if (intSeconds < 10) {
seconds = "0"+intSeconds+" ";
} else {
seconds = intSeconds+" ";
}
timeString = years+months+days+hours+minutes+seconds;
Clock.innerHTML = timeString;
window.setTimeout("tick();", 1000);
}
window.onload = tick;
</SCRIPT>
</head>
<BODY>
<SPAN id="Clock"></SPAN>
</BODY>
</HTML>

2、倒计时时间展示,以双十一倒计时为例:

代码如下:转载自:http://blog.csdn.net/u011415782/article/details/53814517

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head>
<style type="text/css">
div{
font-size:58px;
}
</style>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JS时间倒计时</title>
<script type="text/javascript">
var time_now_server,time_now_client,time_end,time_server_client;
time_end=new Date("2017/11/11 00:00:0");//结束的时间
time_end=time_end.getTime();//获取的是毫秒
time_now_server=new Date();//开始的时间
time_now_server=time_now_server.getTime();
setTimeout("show_time()",1000);
function show_time()
{
var timer = document.getElementById("timer");
var hourid = document.getElementById("hour");
if(!timer){
return ;
}
timer.innerHTML =time_now_server;
var time_now,time_distance,str_time;
var int_day,int_hour,int_minute,int_second;
var time_now=new Date();
time_now=time_now.getTime();
time_distance=time_end-time_now;
if(time_distance>0)
{
int_day=Math.floor(time_distance/86400000)
time_distance-=int_day*86400000;
int_hour=Math.floor(time_distance/3600000)
time_distance-=int_hour*3600000;
int_minute=Math.floor(time_distance/60000)
time_distance-=int_minute*60000;
int_second=Math.floor(time_distance/1000)
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;
str_time=int_day+"天"+int_hour+"小时"+int_minute+"分钟"+int_second+"秒";
timer.innerHTML=str_time;
setTimeout("show_time()",1000);
}
else
{
timer.innerHTML =0;
}
}
</script>
</head>
<body>
<div id="timer"></div>
</body>
</html>


最后

以上就是殷勤未来为你收集整理的HTML当前日期和倒计时展示1、展示当前日期:2、倒计时时间展示,以双十一倒计时为例:的全部内容,希望文章能够帮你解决HTML当前日期和倒计时展示1、展示当前日期:2、倒计时时间展示,以双十一倒计时为例:所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(40)

评论列表共有 0 条评论

立即
投稿
返回
顶部