会飞的鱼

2017
FYS二开大前端

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显示时间代码
标签: JS html

网友评论(2)

很实用的代码,谢谢
免费网上赚钱 4周前 (2018-06-21) 回复
陈双义博客 2个月前 (2018-05-15) 回复