function show(){
var date = new Date()//日期对象
var now = ""
now = date.getFullYear()+"年"//读英文就行了
now = now + (date.getMonth()+1)+"月"//取月的时候取的是当前月-1如果想取当前月+1就可以了
now = now + date.getDate()+"日"
now = now + date.getHours()+"时滚冲"
now = now + date.getMinutes()+"分"
now = now + date.getSeconds()+"秒"
document.getElementById("now").value = now//input的html是now这个字符串
setTimeout("show()",1000)//设置过1000毫秒就是1秒,调用show方法脊备芦
}
</script>
<body onLoad="show()"><!-- 网页加载时调用一次 以后就自动调用了-->
<input id="now" type="text" style="width:200pxtext-align:center" />
<!--把需要加载时间的页面元素的id=‘now’,就可以了-->
</樱带body>
functionyeart(){
var
now=new
Date()
var
year=now.getFullYear()
var
ss=year-2008//设定2008为初始年哪燃首搏份
var
ssc=ss%12
var
ssyear=new
Array("子鼠","丑牛","寅虎","卯兔","辰龙","巳蛇","午马","未羊","申猴","酉鸡","戌狗","亥猪")
document.write(year+"年\n"+ssyear[ssc])
}
[Ctrl+A
全选
注李芹虚:如需引入外部Js需刷新才能执行]
兼容IE,FF,safari,opera等浏览器。在FF浏览器下出现千年虫问题(乎慎109年)已解决,和大家分享一下。1.将以下代码保存成DateJs.js文件,代码如下:var enabled = 0today = new Date()var dayvar 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.getFullYear()) + "年 " + (today.getMonth() + 1 ) + "月 " + today.getDate() + "日 " + day +""
document.write(date)2.在<body>中欲显示的地方加入:<script src="DateJs.js" type="text/javascript" language="javascript"></script>既可。效果如下:今天是: 2009年孙悔 9月 10日 星期四
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)