html天数计数器代码和html显示时间代码

html天数计数器代码

<script language="javascript">
var now=new Date();var spday=new Date(2007,04-1,09);a=(now.getTime()-spday.getTime())/(24*60*60*1000);a=Math.ceil(a); document.write
("<b>"+a+"</b>");</script>天 其中2007,04-1,09  是你要計算的天數起始日~(2007,04-1,09)=(西元年,月-1,日),
(-1)的地方不要更動

html显示时间代码

Clock.js文件
function Clock() {
 var date = new Date();
 this.year = date.getFullYear();
 this.month = date.getMonth() + 1;
 this.date = date.getDate();
 this.day = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六")[date.getDay()];
 this.hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
 this.minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
 this.second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();

this.toString = function() {
  return this.year + "年" + this.month + "月" + this.date + "日 " + this.hour + ":" + this.minute + ":" + this.second + " " + this.day; 
 };
 
 this.toSimpleDate = function() {
  return this.year + "-" + this.month + "-" + this.date;
 };
 
 this.toDetailDate = function() {
  return this.year + "-" + this.month + "-" + this.date + " " + this.hour + ":" + this.minute + ":" + this.second;
 };
 
 this.display = function(ele) {
  var clock = new Clock();
  ele.innerHTML = clock.toString();
  window.setTimeout(function() {clock.display(ele);}, 1000);
 };
}

需要显示时间的页面
<SCRIPT src="js/Clock.js" type=text/javascript></SCRIPT>      //引入Clock.js文件,注意路径
 
<label id=clock></label>       //放入标签,插入时间
<SCRIPT type=text/javascript>      //实例化clock对象
var clock = new Clock();
clock.display(document.getElementById("clock"));
</SCRIPT>

 

本博客所有文章如无特别注明均为原创。作者:亿零复制或转载请以超链接形式注明转自 亿零网-乐享网络,做最好的自己
原文地址《html天数计数器代码和html显示时间代码

相关推荐

发表评论

路人甲
Ctrl+Enter快速提交

网友评论(0)