javascript实现日期星期的显示

Javascript实现日期星期全显示,项目的需要显示日期和星期,下面代码就可以显示当前的日期和星期

None.gif < html >
None.gif
< body >
ExpandedBlockStart.gifContractedBlock.gif
< script  language =javascript > dot.gif
InBlock.gif
<!--
InBlock.giftodayDate 
= new Date();
InBlock.gifdate 
= todayDate.getDate();
InBlock.gifmonth
= todayDate.getMonth() +1;
InBlock.gifyear
= todayDate.getYear();
InBlock.gifdocument.write(
"今天是")
InBlock.gifdocument.write(
"<br>")
InBlock.gif
if(navigator.appName == "Netscape")
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif    document.write(
1900+year);
InBlock.gif    document.write(
"");
InBlock.gif    document.write(month);
InBlock.gif    document.write(
"");
InBlock.gif    document.write(date);
InBlock.gif    document.write(
"");
InBlock.gif    document.write(
"<br>")
ExpandedSubBlockEnd.gif}

InBlock.gif
if(navigator.appVersion.indexOf("MSIE"!= -1)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifdocument.write(year);
InBlock.gifdocument.write(
"");
InBlock.gifdocument.write(month);
InBlock.gifdocument.write(
"");
InBlock.gifdocument.write(date);
InBlock.gifdocument.write(
"");
InBlock.gifdocument.write(
"<br>")
ExpandedSubBlockEnd.gif}

InBlock.gif
if (todayDate.getDay() == 5) document.write("星期五")
InBlock.gif
if (todayDate.getDay() == 6) document.write("星期六")
InBlock.gif
if (todayDate.getDay() == 0) document.write("星期日")
InBlock.gif
if (todayDate.getDay() == 1) document.write("星期一")
InBlock.gif
if (todayDate.getDay() == 2) document.write("星期二")
InBlock.gif
if (todayDate.getDay() == 3) document.write("星期三")
InBlock.gif
if (todayDate.getDay() == 4) document.write("星期四")
InBlock.gif
ExpandedBlockEnd.gif
//--> 
None.gif
</ script >
None.gif 
</ body >
None.gif
</ html >

    todayDate = new Date();

当定义一个新的对象时,通常使用“new”操作符。在这里,就是创建了日期对象。

date = todayDate.getDate();getDate()是Date对象的一种方法,其功能是获得当前的日期。
month= todayDate.getMonth() + 1 ;

 getMonth()是Date对象的一种方法,其功能是获得当前的日期,由于月份是从0开始的,所以这里要“+1”。

year= todayDate.getYear()getYear()是Date对象的一种方法,其功能是获得当前的年份。
if(navigator.appName == "Netscape") { document.write(1900+year); document.write("年"); document.write(month); document.write("月"); document.write(date); document.write("日");
document.write("<br> ") }
如果浏览器是Netscape,输出今天是“year”+“年”+“month”+“月”+“date”+“日”,其中年要加1900。
if(navigator.appVersion.indexOf("MSIE") != -1) { document.write(year); document.write("年"); document.write(month); document.write("月"); document.write(date); document.write("日");
document.write("<br> ") }
如果浏览器是IE,直接输出今天是“year”+“年”+“month”+“月”+“date”+“日”。
if (todayDate.getDay() == 5) document.write("星期五");
if (todayDate.getDay() == 6) document.write("星期六");
if (todayDate.getDay() == 0) document.write("星期日");
if (todayDate.getDay() == 1) document.write("星期一");
if (todayDate.getDay() == 2) document.write("星期二");
if (todayDate.getDay() == 3) document.write("星期三");
if (todayDate.getDay() == 4) document.write("星期四")
getDay()是Date对象的一种方法,其功能是获得当前是星期几。document.write输出今天是“星期几”。


转载于:https://www.cnblogs.com/conquer/archive/2006/11/20/565779.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值