JS网页上显示中英文版日期时间(根据电脑上的时间)

在做一些门户网站的时候可能要加上系统时间.代码网站上到处都是,,我这里也做下记录
<div id="clock"></div> 放时间的DIV
将<body>改成<body onLoad="shownowtime();">

中文版实现效果: 2010年7月29日 9:01:21 星期四
JS代码:

<script language="javascript">
function shownowtime() {
var weekName= new Array("日","一","二","三","四","五","六");
var today=new Date();
var time=today.toLocaleString();
var week=weekName[today.getDay()];
var listdate= time+" 星期"+week;
document.getElementById("clock").innerHTML=listdate;
setTimeout("shownowtime()",1000);
}
</script>




英文版实现效果 Thursday, July 29, 2010 9:00:44 AM
JS代码:

<script language="javascript">
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="AM"
if (hours>=12)
dn="PM"
if (hours>12){
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
//change font size here
var cdate="<small><font color='000000' face='Arial'><b>"+dayarray[day]+", "+montharray[month]+""+daym+", "+year+""+hours+":"+minutes+":"+seconds+""+dn
+"</b></font></small>"
if (document.all)
document.all.clock.innerHTML=cdate
else
document.write(cdate)
}
if (!document.all)
getthedate()
function shownowtime(){
if (document.all)
setInterval("getthedate()",1000)
}
</script>



欢迎转载,原文地址:http://www.lrfun.com/html/technology/cssjs/2015/0128/6.html

上一篇:html 滚动标签marquee
下一篇:CSS文字超出一定范围以省略号显示