如何在js里获取系统时间,并在html中应用;
<divid='date'>现在时间是:<span><!--在这里实现时间--></span>最好能提供把js代码和html代码非常感谢...
<div id='date'>现在时间是: <span><!--在这里实现时间--></span>
最好能提供把js代码和html代码
非常感谢 展开
最好能提供把js代码和html代码
非常感谢 展开
3个回答
展开全部
年 月 日 时 分 秒 星期 。 如果按楼主要求,星期换下就可以,也就是
var ndate = years+"年"+month+"月"+days+"日 "+hours+":"+minutes+":"+seconds+" "+week;
这句 ,换成
var ndate = years+"年"+month+"月"+days+"日 "+week+" "+hours+":"+minutes+":"+seconds;
<html>
<head>
<title></title>
<script language="javascript">
function getCurDate()
{
var d = new Date();
var week;
switch (d.getDay()){
case 1: week="星期一"; break;
case 2: week="星期二"; break;
case 3: week="星期三"; break;
case 4: week="星期四"; break;
case 5: week="星期五"; break;
case 6: week="星期六"; break;
default: week="星期天";
}
var years = d.getYear();
var month = add_zero(d.getMonth()+1);
var days = add_zero(d.getDate());
var hours = add_zero(d.getHours());
var minutes = add_zero(d.getMinutes());
var seconds=add_zero(d.getSeconds());
var ndate = years+"年"+month+"月"+days+"日 "+hours+":"+minutes+":"+seconds+" "+week;
divT.innerHTML= ndate;
}
function add_zero(temp)
{
if(temp<10) return "0"+temp;
else return temp;
}
setInterval("getCurDate()",100);
</script>
</head>
<body>
<div id="divT"></div>
</body>
</html>
var ndate = years+"年"+month+"月"+days+"日 "+hours+":"+minutes+":"+seconds+" "+week;
这句 ,换成
var ndate = years+"年"+month+"月"+days+"日 "+week+" "+hours+":"+minutes+":"+seconds;
<html>
<head>
<title></title>
<script language="javascript">
function getCurDate()
{
var d = new Date();
var week;
switch (d.getDay()){
case 1: week="星期一"; break;
case 2: week="星期二"; break;
case 3: week="星期三"; break;
case 4: week="星期四"; break;
case 5: week="星期五"; break;
case 6: week="星期六"; break;
default: week="星期天";
}
var years = d.getYear();
var month = add_zero(d.getMonth()+1);
var days = add_zero(d.getDate());
var hours = add_zero(d.getHours());
var minutes = add_zero(d.getMinutes());
var seconds=add_zero(d.getSeconds());
var ndate = years+"年"+month+"月"+days+"日 "+hours+":"+minutes+":"+seconds+" "+week;
divT.innerHTML= ndate;
}
function add_zero(temp)
{
if(temp<10) return "0"+temp;
else return temp;
}
setInterval("getCurDate()",100);
</script>
</head>
<body>
<div id="divT"></div>
</body>
</html>
展开全部
<div id='date'><script>getdates();</script></div>
<script language="javascript">
function getdates()
{
var w_array=new Array("星期天","星期一","星期二","星期三","星期四","星期五","星期六");
var d=new Date();
var year=d.getFullYear();
var month=d.getMonth()+1;
var day=d.getDate();
var week=d.getDay();
var h=d.getHours();
var mins=d.getMinutes();
var s=d.getSeconds();
if(month<10) month="0" + month
if(day<10) month="0" + day
if(h<10) h="0" + h
if(mins<10) mins="0" + mins
if(s<10) s="0" + s
var shows="现在时间是: <span>" + year + "-" + month + "-" + day + " " + h + ":" + mins + ":" + s + " " + w_array[week] + "</span>";
document.getElementById("date").innerHTML=shows;
setTimeout("getdates()",1000);
}
getdates();
</script>
<script language="javascript">
function getdates()
{
var w_array=new Array("星期天","星期一","星期二","星期三","星期四","星期五","星期六");
var d=new Date();
var year=d.getFullYear();
var month=d.getMonth()+1;
var day=d.getDate();
var week=d.getDay();
var h=d.getHours();
var mins=d.getMinutes();
var s=d.getSeconds();
if(month<10) month="0" + month
if(day<10) month="0" + day
if(h<10) h="0" + h
if(mins<10) mins="0" + mins
if(s<10) s="0" + s
var shows="现在时间是: <span>" + year + "-" + month + "-" + day + " " + h + ":" + mins + ":" + s + " " + w_array[week] + "</span>";
document.getElementById("date").innerHTML=shows;
setTimeout("getdates()",1000);
}
getdates();
</script>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
var myDate = new Date();
myDate.getYear(); //获取当前年份(2位)
myDate.getFullYear(); //获取完整的年份(4位,1970-????)
myDate.getMonth(); //获取当前月份(0-11,0代表1月)
myDate.getDate(); //获取当前日(1-31)
myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
myDate.getTime(); //获取当前时间(从1970.1.1开始的毫秒数)
myDate.getHours(); //获取当前小时数(0-23)
myDate.getMinutes(); //获取当前分钟数(0-59)
myDate.getSeconds(); //获取当前秒数(0-59)
myDate.getMilliseconds(); //获取当前毫秒数(0-999)
myDate.toLocaleDateString(); //获取当前日期
var mytime=myDate.toLocaleTimeString(); //获取当前时间
myDate.toLocaleString( ); //获取日期与时间
myDate.getYear(); //获取当前年份(2位)
myDate.getFullYear(); //获取完整的年份(4位,1970-????)
myDate.getMonth(); //获取当前月份(0-11,0代表1月)
myDate.getDate(); //获取当前日(1-31)
myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
myDate.getTime(); //获取当前时间(从1970.1.1开始的毫秒数)
myDate.getHours(); //获取当前小时数(0-23)
myDate.getMinutes(); //获取当前分钟数(0-59)
myDate.getSeconds(); //获取当前秒数(0-59)
myDate.getMilliseconds(); //获取当前毫秒数(0-999)
myDate.toLocaleDateString(); //获取当前日期
var mytime=myDate.toLocaleTimeString(); //获取当前时间
myDate.toLocaleString( ); //获取日期与时间
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询