飞龙博客

妙法莲华经

调用javascript实现日期星期的显示

feilong.org 修订于2009-07-30 07:44:00 188 次浏览

飞龙(www.feilong.org)为客户做一个企业网站,涉及调用javascript实现在网页中自动显示当前日期和星期查看相关资料,一般采用调用外部js文件来实现。本日志修订地址:http://feilong.org/javascript-date 。飞龙发现在网页内部需要显示日期星期的地方,只需写如下调用日期星期代码:<script language="JavaScript" src="js/date.js" mce_src="js/date.js" type="text/javascript"></script> 飞龙友情提示:其中的 document.write("<br>") 如果去掉的话,就可以实现日期星期在一行显示。 里面的src="js/date.js" mce_src="js/date.js",可以根据你js文件的存放位置相应调整。

下面是调用的日期星期js文件内容

todayDate = new Date();
date = todayDate.getDate();
month= todayDate.getMonth() +1;
year= todayDate.getYear();
document.write("今天是")
document.write("<br>")

if(navigator.appName == "Netscape")
{
document.write(1900+year);
document.write("年");
document.write(month);
document.write("月");
document.write(date);
document.write("日");
document.write("<br>")
}

if(navigator.appVersion.indexOf("MSIE") != -1)
{
document.write(year);
document.write("年");
document.write(month);
document.write("月");
document.write(date);
document.write("日");
}

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("星期四")

如果想知道如何在网页里面添加天气预报代码,请参考这里:http://feilong.org/weather-code。本文演示:http://feilong.org/code/JavaScript-date.htm

博主:飞龙.org
更新:http://feilong.org/javascript-date
参考:http://www.blogjava.net/DreamAngel
加入收藏夹,查看更方便,记住了feilong.org

更新网址:https://feilong.org/javascript-date
最初发布:20090730 07:44:00 feilong.org 于广州

加入收藏夹,查看更方便。

所在分类: 网站开发

新作:

旧文: