网页代码,怎么实现显示年月日?
发布网友
发布时间:2022-04-29 19:32
我来回答
共1个回答
热心网友
时间:2022-06-21 06:15
注意JS是区分大小写的,并且分号是英文半角的
<html>
<head>
<title>例子2222</title>
<style><!--
body {font-size:9pt;color:blue}
</style>
<script language="javascript">
var today;
var day;
var date;
today=new 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="星期六 ";
date="今天是"+today.getYear()+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日 ";
document.write(date);
document.write(day);
</script>
</head>
<body>
</body>
</html>