JS网页上显示中英文版日期时间(根据电脑上的时间)
发表时间: 2015-01-28 11:10:45 | 浏览次数:
在做一些门户网站的时候可能要加上系统时间.代码网站上到处都是,,我这里也做下记录<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>
上一篇:html 滚动标签marquee
下一篇:CSS文字超出一定范围以省略号显示