复制代码 代码如下,JavaScript实现页面实时显示当前时间&lt

发布时间:2020-01-20  栏目:新葡京32450网址  评论:0 Comments

<html>
<body>
<span id=”liveclock”></span>
<SCRIPT language=javascript>
function showtime(){
var Digital=new Date();
var years=Digital.getYear();
var months=Digital.getMonth()+1;
var days=Digital.getDate();
var hours=Digital.getHours();
var minutes=Digital.getMinutes();
var seconds=Digital.getSeconds();
if(months<=9)
  months=”0″+months;
if(minutes<=9)
  minutes=”0″+minutes;
if(seconds<=9)
  seconds=”0″+seconds;
  myclock=years+”年”+months+”月”+days+”日 “+hours+”:”+minutes+”:”+seconds;
if(document.layers){document.layers.liveclock.document.write(myclock)
  document.layers.liveclock.document.close();
}else if(document.all)
  liveclock.innerHTML=myclock;
  setTimeout(“showtime()”,1000);
}
showtime();
</SCRIPT>

<html>
<head>
<title>JavaScript实现页面实时显示当前时间</title>
</head>
<body>
<script language=”javascript”>
function showtime()
{
var today,hour,second,minute,year,month,date;
var strDate ;
today=new Date();
var n_day = today.getDay();
switch (n_day)
{
case 0:{
strDate = “星期日”
}break;
case 1:{
strDate = “星期一”
}break;
case 2:{
strDate =”星期二”
}break;
case 3:{
strDate = “星期三”
}break;
case 4:{
strDate = “星期四”
}break;
case 5:{
strDate = “星期五”
}break;
case 6:{
strDate = “星期六”
}break;
case 7:{
strDate = “星期日”
}break;
}
year = today.getYear();
month = today.getMonth()+1;
date = today.getDate();
hour = today.getHours();
minute =today.getMinutes();
second = today.getSeconds();
if(month<10) month=”0″+month;
if(date<10) date=”0″+date;
if(hour<10) hour=”0″+hour;
if(minute<10) minute=”0″+minute;
if(second<10) second=”0″+second;
document.getElementById(‘time’).innerHTML = year + “年” + month + “月” +
date + “日 ” + strDate +” ” + hour + “:” + minute + “:” + second;
//显示时间
setTimeout(“showtime();”, 1000); //设定函数自动执行时间为 1000 ms(1 s)
}
</script>
<div id=”time”></div>
<script language=”javascript”> showtime();</script>
</body>
</html>

来自:

您可能感兴趣的文章:

  • JS简单测试循环运行时间的方法
  • js实现网页倒计时、网站已运行时间功能的代码3例
  • js查看一个函数的执行时间实例代码
  • js执行时间查看器
  • 获取焦点时,利用js定时器设定时间执行动作
  • js 页面执行时间计算代码
  • 用js计算页面执行时间的函数
  • 计算100000数组js脚本的执行时间
  • js获取当前时间显示在页面上并每秒刷新
  • 用js实现计算加载页面所用的时间
  • 页面实时更新时间的JS实例代码
  • Javascript实现的StopWatch功能示例

return newDate;
}
</script>
</head>
<body>
<script language=”javascript” type=”text/javascript”>
//调用
document.writeln(formatDateTime(“2014/04/16 22:34:45”, 11));
</script>
</body>
</html>

</body>
</html>

代码如下: html head
titleJavaScript实现页面实时显示当前时间/title /head body script
language=”javascript” function showtime() { var
today,hour,second,m…

<%@LANGUAGE=”VBSCRIPT” CODEPAGE=”936″%>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″
/>
<title>显示当前日期时间[不断变化]</title>
</head>
<body>
<script language=”JavaScript” type=”text/javascript”>
<!–
calendar = new Date();
day = calendar.getDay();
month = calendar.getMonth();
date = calendar.getDate();
year = calendar.getYear();
if (year< 100) year = 1900 + year;
cent = parseInt(year/100);
g = year % 19;
k = parseInt((cent – 17)/25);
i = (cent – parseInt(cent/4) – parseInt((cent – k)/3) + 19*g + 15) %
30;
i = i – parseInt(i/28)*(1 –
parseInt(i/28)*parseInt(29/(i+1))*parseInt((21-g)/11));
j = (year + parseInt(year/4) + i + 2 – cent + parseInt(cent/4)) % 7;
l = i – j;
emonth = 3 + parseInt((l + 40)/44);
edate = l + 28 – 31*parseInt((emonth/4));
emonth–;
var dayname = new Array (“星期日”, “星期一”, “星期二”, “星期三”,
“星期四”, “星期五”, “星期六”);
var monthname =
new Array
(“1月”,”2月”,”3月”,”4月”,”5月”,”6月”,”7月”,”8月”,”9月”,”10月”,”11月”,”12月”
);
document.write(year +”年”);
document.write(monthname[month]);
document.write(date + “日”+” “);
document.write(dayname[day]);
//–>
</script>
<script language=”JavaScript” type=”text/javascript”>
<!–
document.write(“<span id=’clock’></span>”);
var now,hours,minutes,seconds,timeValue;
function showtime(){
now = new Date();
hours = now.getHours();
minutes = now.getMinutes();
seconds = now.getSeconds();
timeValue = (hours >= 12) ? ” 下午 ” : ” 上午 “;
timeValue += ((hours > 12) ? hours – 12 : hours) + “点”;
timeValue += ((minutes <10)?”0″:””) + minutes+”分”;
timeValue += ((seconds <10)?”0″:””) + seconds+”秒”;
clock.innerHTML = timeValue;
setTimeout(“showtime()”,100);
}
showtime();
//–>
</script>
</body>
</html>

复制代码 代码如下:

days = newDate.getDate();
if (Number(days) < 10) days = “0” + days;

复制代码 代码如下:

效果:时间不断更新!

<html>
<head>
<title>JavaScript实现页面实时显示当前时间</title>
</head>
<body>
<script language=”javascript”>
function showtime()
{
var today,hour,second,minute,year,month,date;
var strDate ;
today=new Date();
var n_day = today.getDay();
switch (n_day)
{
case 0:{
strDate = “星期日”
}break;
case 1:{
strDate = “星期一”
}break;
case 2:{
strDate =”星期二”
}break;
case 3:{
strDate = “星期三”
}break;
case 4:{
strDate = “星期四”
}break;
case 5:{
strDate = “星期五”
}break;
case 6:{
strDate = “星期六”
}break;
case 7:{
strDate = “星期日”
}break;
}
year = today.getYear();
month = today.getMonth()+1;
date = today.getDate();
hour = today.getHours();
minute =today.getMinutes();
second = today.getSeconds();
if(month<10) month=”0″+month;
if(date<10) date=”0″+date;
if(hour<10) hour=”0″+hour;
if(minute<10) minute=”0″+minute;
if(second<10) second=”0″+second;
document.getElementById(‘time’).innerHTML = year + “年” + month + “月” +
date + “日 ” + strDate +” ” + hour + “:” + minute + “:” + second;
//显示时间
setTimeout(“showtime();”, 1000); //设定函数自动执行时间为 1000 ms(1 s)
}
</script>
<div id=”time”></div>
<script language=”javascript”> showtime();</script>
</body>
</html>

newDate = years + “/” + month + “/” + days;
break;
case 7: //格式:MM/dd HH:mm
month = newDate.getMonth();
if (Number(month) < 10) month = “0” + month;

将代码保存为showdatetime.asp即可!

month = newDate.getMonth();
if (Number(month) < 10) month = “0” + month;

newDate = hours + “:” + minutes + “:” + seconds;
break;
case 4: //格式:HH:mm
hours = newDate.getHours();
if (Number(hours) < 10) hours = “0” + hours;

minutes = newDate.getMinutes();
if (Number(minutes) < 10) minutes = “0” + minutes;

hours = newDate.getHours();
if (Number(hours) < 10) hours = “0” + hours;

days = newDate.getDate();
if (Number(days) < 10) days = “0” + days;

seconds = newDate.getSeconds();
if (Number(seconds) < 10) seconds = “0” + seconds;

days = newDate.getDate();
if (Number(days) < 10) days = “0” + days;

相关文章

留下评论

网站地图xml地图