如果在网页中插入一个动态更新的时间,有年月日和星期的?

crazyjeans 2003-10-18 12:51:09
我知道要插入一段javascript,只是不会编写,请大侠们给段代码可以吗?如果有DMX的插件最好,谢了!
...全文
166 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
CsdnPlayer 2003-10-25
  • 打赏
  • 举报
回复
mark
lqlolc 2003-10-18
  • 打赏
  • 举报
回复
例子1:

<script language="JavaScript"><!--
now = new Date()
hour = now.getHours()
if (hour < 12) {
document.write("现在是: " + now.toLocaleString())
} else if (hour < 18){
document.write("现在是: " + now.toLocaleString())
} else if (hour >= 18) {
document.write("现在是: " + now.toLocaleString())
}
// --></script>


例子2:

<script language="JavaScript"><!--
var enabled = 0; today = new Date();
var day; var date;
if(today.getDay()==0) day = "星期日"
if(today.getDay()==1) day = "星期一"
if(today.getDay()==2) day = "星期二"
if(today.getDay()==3) day = "星期三"
if(today.getDay()==4) day = "星期四"
if(today.getDay()==5) day = "星期五"
if(today.getDay()==6) day = "星期六"
document.fgColor = "000000";
date = " 今天是 " + (today.getYear()) + " 年" + (today.getMonth() + 1 ) + " 月 " + today.getDate() + " 日 " + day +"";
document.write("<CENTER><TABLE BORDER=2 BGCOLOR=000000><TH><FONT COLOR=ffffff>")
document.write("<CENTER>" + date.fontsize(3) + "</CENTER>");
document.write("</FONT></TH></TABLE></center><P>")// -->
</script>

例子3:

<script language="JavaScript"> <!---
today=new Date();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
var timeValue = "<FONT COLOR=black>" + ((hours >12) ? hours -12 :hours); timeValue += ((minutes < 10) ? "<BLINK><FONT COLOR=black>:</FONT></BLINK>0" : "<BLINK><FONT COLOR=black>:</FONT></BLINK>") + minutes+"</FONT></FONT>";
timeValue += (hours >= 12) ? "<FONT COLOR=blue><I><B>pm</B></I></FONT>" : "<FONT COLOR=blue><B><I>am</I></B></FONT>";
function initArray(){
this.length=initArray.arguments.length
for(var i=0;i<this.length;i++)
this[i+1]=initArray.arguments[i] }
var d=new initArray("<font color=RED>星期日","<font color=black>星期一","<font color=black>星期二","<font color=black>星期三","<font color=black>星期四","<font color=black>星期五","<font color=GREEN>星期六"); document.write("<font color=black>19<font color=black>",today.getYear(),"<font color=red>年","<font color=black>",today.getMonth()+1,"<font color=red>月","<font color=black>",today.getDate(),"<font color=red>日 </FONT>",d[today.getDay()+1]," ",timeValue); //--></script>
看哪个合适要哪个
xuzhe1111 2003-10-18
  • 打赏
  • 举报
回复
<script language="JavaScript1.2">

<!--

if (document.layers)

document.write('<ilayer id="clockmain" height=20><layer id="clock" width="100%"></layer></ilayer>');

else

document.write("<div><span id='clock'></span></div>");

var now,hours,minutes,seconds,timeValue;

function showtime(){

if (!document.layers&&!document.all) return;

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 + " 秒";

if (document.layers){

document.clockmain.document.clock.document.write(timeValue);

document.clockmain.document.clock.document.close();

}

else if (document.all)

clock.innerHTML = timeValue;

setTimeout("showtime()",100);

}

window.onload=showtime;

//-->

</script>

1,451

社区成员

发帖
与我相关
我的任务
社区描述
多媒体/设计/Flash/Silverlight 开发 图象工具使用
社区管理员
  • 图象工具使用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧