求js获取服务器时间(动态更新) 求js获取服务器时间(动态更新) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 var timerID = null var timerRunning = false function MakeArray(size) { this.length = size; for(var i = 1; i <= size; i++) { this[i] = ""; } return this; } function stopclock (){ if(timerRunning) clearTimeout(timerID); timerRunning = false } function showtime () { var now = new Date(); var year = now.getYear(); var month = now.getMonth() + 1; var date = now.getDate(); var hours = now.getHours(); var minutes = now.getMinutes(); var seconds = now.getSeconds(); var day = now.getDay(); Day = new MakeArray(7); Day[0]="星期天"; Day[1]="星期一"; Day[2]="星期二"; Day[3]="星期三"; Day[4]="星期四"; Day[5]="星期五"; Day[6]="星期六"; var timeValue = ""; timeValue += year + "年"; timeValue += ((month < 10) ? "0" : "") + month + "月"; timeValue += date + "日 "; timeValue += (Day[day]) + " "; timeValue += ((hours <= 12) ? hours : hours - 12); timeValue += ((minutes < 10) ? ":0" : ":") + minutes; timeValue += ((seconds < 10) ? ":0" : ":") + seconds; timeValue += (hours < 12) ? "上午" : "下午"; document.getElementById("datetime").innerText=timeValue; timerID = setTimeout("showtime()",1000); timerRunning = true } function startclock () { stopclock(); showtime() }timevalue就是系统当前时间 <mce:script language="JavaScript"><!-- //定义一个tick函数,以获取系统的时间 function tick() { var year,month,day,hours,minutes,seconds,ap; var intYear,intMonth,intDay,intHours,intMinutes,intSeconds; var today; today=new Date(); intYear=today.getYear()+1900; intMonth=today.getMonth()+1; intDay=today.getDate(); intHours=today.getHours(); intMinutes=today.getMinutes(); intSeconds=today.getSeconds(); //获取系统时间的小时数 if(intHours==0) { hours=intHours+":"; ap="凌晨"; } else if(intHours<12) { hours=intHours+":"; ap="早晨"; } else if(intHours==12) { hours=intHours+":"; ap="中午"; } else { intHours=intHours-12; hours=intHours+":"; ap="下午"; } //获取系统时间的分数 if(intMinutes<10) { minutes="0"+intMinutes+":"; } else { minutes=intMinutes+":"; } //获取系统时间的秒数 if(intSeconds<10) { seconds="0"+intSeconds+" "; } else { seconds=intSeconds+" "; } timeString=intYear+'年'+intMonth+'月'+intDay+'日'+hours+minutes+seconds+ap; document.getElementById("Clock").innerHTML=timeString; //每隔0.1秒钟执行一次tick函数 window.setTimeout("tick()",100); } window.onload=tick; //document.getElementById("Clock").innerHTML=timeString; // --></mce:script> body中的div为:<div id="Clock"></div> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> New Document </TITLE><SCRIPT LANGUAGE="JavaScript"><!-- function showtime() { var now = new Date(); var year = now.getYear(); //年 var month = now.getMonth() + 1; //月 var date = now.getDate(); //日 var hours = now.getHours(); //小时 var minutes = now.getMinutes(); //分 var seconds = now.getSeconds(); //秒 var day = now.getDay(); Day = new Array(7); Day[0]="星期天"; Day[1]="星期一"; Day[2]="星期二"; Day[3]="星期三"; Day[4]="星期四"; Day[5]="星期五"; Day[6]="星期六"; var timeValue = ""; timeValue += year + "年"; timeValue += ((month < 10) ? "0" : "") + month + "月"; timeValue += date + "日 "; timeValue += (Day[day]) + " "; timeValue += ((hours <= 12) ? hours : hours - 12); timeValue += ((minutes < 10) ? ":0" : ":") + minutes; timeValue += ((seconds < 10) ? ":0" : ":") + seconds; timeValue += (hours < 12) ? "上午" : "下午"; document.body.innerHTML = timeValue; setTimeout("showtime()",1000); } setTimeout("showtime()",1000);//--></SCRIPT></HEAD><BODY onLoad="showtime()"></BODY></HTML> 楼上的这些都是获得客户端的时间吧!!假如客户端的时间一改,那面页面上显示的也就是改之后的时间了楼主看看下面的链接http://www.code-123.com/html/2009727175322580.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> New Document </TITLE><SCRIPT LANGUAGE="JavaScript"><!-- function showtime() { var now = new Date(); var year = now.getYear(); //年 var month = now.getMonth() + 1; //月 var date = now.getDate(); //日 var hours = now.getHours(); //小时 var minutes = now.getMinutes(); //分 var seconds = now.getSeconds(); //秒 var day = now.getDay(); Day = new Array(7); Day[0]="星期天"; Day[1]="星期一"; Day[2]="星期二"; Day[3]="星期三"; Day[4]="星期四"; Day[5]="星期五"; Day[6]="星期六"; var timeValue = ""; timeValue += year + "年"; timeValue += ((month < 10) ? "0" : "") + month + "月"; timeValue += date + "日 "; timeValue += (Day[day]) + " "; timeValue += ((hours <= 12) ? hours : hours - 12); timeValue += ((minutes < 10) ? ":0" : ":") + minutes; timeValue += ((seconds < 10) ? ":0" : ":") + seconds; timeValue += (hours < 12) ? "上午" : "下午"; document.body.innerHTML = timeValue; setTimeout("showtime()",1000); } setTimeout("showtime()",1000);//--></SCRIPT></HEAD><BODY onLoad="showtime()"></BODY></HTML> 获取服务器时间,就ajax返回服务器时间呗 Jquery Load 问题【急急急】 多个相同class 的时候 只更改当前鼠标悬停的class样式 关于js和<%%> 下面这两个循环怎么改进才能运行快点 求改正个javascript 如何在框架中传递参数? 求四级连动的代码 哪下情况 如何从弹出一个页面,在转回原来的页面? 在线等待!!function()中的if语句不起作用!!进来看看,不胜感激!! javascript中事件方法的使用 多个图片的高度如何赋值给表单呢?
var timerRunning = false
function MakeArray(size)
{
this.length = size;
for(var i = 1; i <= size; i++)
{
this[i] = "";
}
return this;
}
function stopclock (){
if(timerRunning)
clearTimeout(timerID);
timerRunning = false
}
function showtime () {
var now = new Date();
var year = now.getYear();
var month = now.getMonth() + 1;
var date = now.getDate();
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var day = now.getDay();
Day = new MakeArray(7);
Day[0]="星期天";
Day[1]="星期一";
Day[2]="星期二";
Day[3]="星期三";
Day[4]="星期四";
Day[5]="星期五";
Day[6]="星期六";
var timeValue = "";
timeValue += year + "年";
timeValue += ((month < 10) ? "0" : "") + month + "月";
timeValue += date + "日 ";
timeValue += (Day[day]) + " ";
timeValue += ((hours <= 12) ? hours : hours - 12);
timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
timeValue += (hours < 12) ? "上午" : "下午";
document.getElementById("datetime").innerText=timeValue;
timerID = setTimeout("showtime()",1000);
timerRunning = true
}
function startclock () {
stopclock();
showtime()
}
timevalue就是系统当前时间
<mce:script language="JavaScript"><!--
//定义一个tick函数,以获取系统的时间
function tick()
{
var year,month,day,hours,minutes,seconds,ap;
var intYear,intMonth,intDay,intHours,intMinutes,intSeconds;
var today;
today=new Date();
intYear=today.getYear()+1900;
intMonth=today.getMonth()+1;
intDay=today.getDate();
intHours=today.getHours();
intMinutes=today.getMinutes();
intSeconds=today.getSeconds();
//获取系统时间的小时数
if(intHours==0)
{
hours=intHours+":";
ap="凌晨";
}
else if(intHours<12)
{
hours=intHours+":";
ap="早晨";
}
else if(intHours==12)
{
hours=intHours+":";
ap="中午";
}
else
{
intHours=intHours-12;
hours=intHours+":";
ap="下午";
}
//获取系统时间的分数
if(intMinutes<10)
{
minutes="0"+intMinutes+":";
}
else
{
minutes=intMinutes+":";
}
//获取系统时间的秒数
if(intSeconds<10)
{
seconds="0"+intSeconds+" ";
}
else
{
seconds=intSeconds+" ";
}
timeString=intYear+'年'+intMonth+'月'+intDay+'日'+hours+minutes+seconds+ap;
document.getElementById("Clock").innerHTML=timeString;
//每隔0.1秒钟执行一次tick函数
window.setTimeout("tick()",100);
}
window.onload=tick;
//document.getElementById("Clock").innerHTML=timeString;
// --></mce:script>
body中的div为:<div id="Clock"></div>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function showtime() {
var now = new Date();
var year = now.getYear(); //年
var month = now.getMonth() + 1; //月
var date = now.getDate(); //日
var hours = now.getHours(); //小时
var minutes = now.getMinutes(); //分
var seconds = now.getSeconds(); //秒
var day = now.getDay();
Day = new Array(7);
Day[0]="星期天";
Day[1]="星期一";
Day[2]="星期二";
Day[3]="星期三";
Day[4]="星期四";
Day[5]="星期五";
Day[6]="星期六";
var timeValue = "";
timeValue += year + "年";
timeValue += ((month < 10) ? "0" : "") + month + "月";
timeValue += date + "日 ";
timeValue += (Day[day]) + " ";
timeValue += ((hours <= 12) ? hours : hours - 12);
timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
timeValue += (hours < 12) ? "上午" : "下午";
document.body.innerHTML = timeValue;
setTimeout("showtime()",1000);
}
setTimeout("showtime()",1000);
//-->
</SCRIPT>
</HEAD><BODY onLoad="showtime()">
</BODY>
</HTML>
http://www.code-123.com/html/2009727175322580.html
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function showtime() {
var now = new Date();
var year = now.getYear(); //年
var month = now.getMonth() + 1; //月
var date = now.getDate(); //日
var hours = now.getHours(); //小时
var minutes = now.getMinutes(); //分
var seconds = now.getSeconds(); //秒
var day = now.getDay();
Day = new Array(7);
Day[0]="星期天";
Day[1]="星期一";
Day[2]="星期二";
Day[3]="星期三";
Day[4]="星期四";
Day[5]="星期五";
Day[6]="星期六";
var timeValue = "";
timeValue += year + "年";
timeValue += ((month < 10) ? "0" : "") + month + "月";
timeValue += date + "日 ";
timeValue += (Day[day]) + " ";
timeValue += ((hours <= 12) ? hours : hours - 12);
timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
timeValue += ((seconds < 10) ? ":0" : ":") + seconds;
timeValue += (hours < 12) ? "上午" : "下午";
document.body.innerHTML = timeValue;
setTimeout("showtime()",1000);
}
setTimeout("showtime()",1000);
//-->
</SCRIPT>
</HEAD><BODY onLoad="showtime()">
</BODY>
</HTML>