html+js 在页面同步服务器时间
2016-08-22 11:14
225 查看
将以下的代码 放置html页面中!
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/mad.gif)
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/mad.gif)
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/mad.gif)
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/mad.gif)
,, 将上面的代码复制完以后 大家来看看浏览器中的效果吧!
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/mad.gif)
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/mad.gif)
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/mad.gif)
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/mad.gif)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title></title> </head> <div id="showtimes"></div> <script type="text/javascript" language="javascript"> function show_cur_times(){ //获取当前日期 var date_time = new Date(); //定义星期 var week; //switch判断 switch (date_time.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="星期天"; break; } //年 var year = date_time.getFullYear(); //判断小于10,前面补0 if(year<10){ year="0"+year; } //月 var month = date_time.getMonth()+1; //判断小于10,前面补0 if(month<10){ month="0"+month; } //日 var day = date_time.getDate(); //判断小于10,前面补0 if(day<10){ day="0"+day; } //时 var hours =date_time.getHours(); //判断小于10,前面补0 if(hours<10){ hours="0"+hours; } //分 var minutes =date_time.getMinutes(); //判断小于10,前面补0 if(minutes<10){ minutes="0"+minutes; } //秒 var seconds=date_time.getSeconds(); //判断小于10,前面补0 if(seconds<10){ seconds="0"+seconds; } //拼接年月日时分秒 var date_str = year+"年"+month+"月"+day+"日 "+hours+":"+minutes+":"+seconds+" "+week; //显示在id为showtimes的容器里 document.getElementById("showtimes").innerHTML= date_str; } //设置1秒调用一次show_cur_times函数 setInterval("show_cur_times()",100); </script> <body> </body> </html>
,, 将上面的代码复制完以后 大家来看看浏览器中的效果吧!
相关文章推荐
- html+js 在页面同步服务器时间
- 在html页面上使用ajax传递json数据到基于express框架(node.js)的服务器
- js实现html页面显示时间的定时刷新
- js 实现页面时间与当前时间同步
- html页面显示服务器时间
- JS实现web页面的导航栏时间与本地同步,实时更新!
- js 计时器,时间与服务器同步
- JS实现HTML页面中动态显示当前时间完整示例
- 在html中获得本地时间的js代码,重要的是他能同步,而不是一时间的获取,然后以静态的方式体现
- JS代码,将终端用户(Web 页面的查看者)的计算机时间置于一个按钮 Web 服务器控件上
- Jacascript 同步服务器时间与页面
- js将本地时间与服务器时间同步
- [原创]实现与服务器时间同步的跨平台JS脚本 支持IE , firefox , Opera ,Netscape 等主流浏览器
- 用js计算页面执行时间的函数
- 倒计时--实现服务器时间同步
- 利用js方法实现html静态页面间参数传递
- 页面上显示当前的时间的js
- [问题-unfinished],怎样使动态改变的js里的document.write任意时间都可以显示在页面上, 问题是不在appendChild前面加一个alert() , append上去的js中的document.write语句通通无效
- 取到服务器时间的JS脚本给客户端显示时间
- [Web2.0]html页面如何通过js加载后台信息