<div align="center" class="STYLE9">欢迎光租嫌敏临,今天是:
<script language=JavaScript>
today=new Date()
function initArray(){
this.length=initArray.arguments.length
for(var i=0i<this.lengthi++)
this[i+1]=initArray.arguments[i] }
var d=new initArray(
"星期日",
"星期一",
"星期二",
"星期三",
"星期四",
"星期五",
"星期六")
document.write(
"<font color=yellow style='font-size:9ptfont-family: 宋体'>",
today.getYear(),"年",
today.getMonth()+1,"月"者念,
today.getDate(),"日",
d[today.getDay()+1],
"</font>" )
</script>
</div>
效果图:
代码截图:(关键部分用框框标出)
源码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>
<span id="date"></span><br>
<span id="week"></span>
脊衫 </div>
<script>
var showDate = document.getElementById('date') // 获取页面元素
var showWeek = document.getElementById('week') // 获取页面元素
var time = new Date()
var year = time.getFullYear() //获取年份
var month = correctDate(time.getMonth() + 1) //获取月份
var day = correctDate(time.getDate()) //获取日期
var date = "今天是" + year + "年" + month + "月" + day + "日"
var week = time.getDay() // 获取星期几,返回亮野巧的是0/1/2/3/4/5/6 0代表周日
var weeks = [ "星期日","星期一","星期二","星期三","星期四","星期五","星期六"]
var toWeek = weeks[week] // 获取今日星期
showDate.innerHTML = date // 将日期显示在页面
showWeek.innerHTML = toWeek // 将星期显示在页面
/* 这是一个规范数字的函数:
当时间小于10时,在数字前面加上0,统一都是用两个数字表示,
比如3月5日就显示03月05日
*/
function correctDate(date){
if(date<10){
敬键 return '0'+date
}
return date
}
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<div id="time"></div>
<script language="javascript" type="text/javascript">
function setTime(){
var dt=new Date()
var arr_week=new Array("星期日","星期一","星期二"圆亮桥,"星期三","星期四","星期五","星期六")
var strWeek=arr_week[dt.getDay()]
var strHour=dt.getHours()
var strMinutes=dt.getMinutes()
var strSeconds=dt.getSeconds()
if (strMinutes<10) strMinutes="0"+strMinutes
if (strSeconds<10) strSeconds="0"+strSeconds
var strYear=dt.getFullYear()+"年"
var strMonth=(dt.getMonth()+1)+"月"
var strDay=dt.getDate()+"日"
var strTime=strHour+":"+strMinutes+":"+strSeconds
time.innerHTML="现在是:"+strYear+strMonth+strDay+" "橘猛+strTime+" "+strWeek /* time是上面DIV的ID值,看要把它放在网页哪边键乎可以换了*/
}
setInterval("setTime()",1000)/* 这个是跳动函数,后面是多久跳以毫秒,1000就是一秒跳动 */
</script>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)