因为不懂PHP所以请各位详细些.最好是告诉我用的方法.如何使用.拿过来就可以用.谢谢了.
我现在有一个静态的HTML需求动态的显示服务器时间.服务器可以运行PHP.
想请各位帮忙写一个PHP时间.我在HTML中显示.
我现在用到的是:var XmlHttp;//创建XMLHTTP对象
if(window.XMLHttpRequest) {//表示当前浏览器不是ie,如chrome,firefox
XmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {//表示当前浏览器是IE
XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}XmlHttp.open("HEAD","http://localhost",false);//从哪个服务器上获取时间
XmlHttp.send(); //连接服务器
var offset = Date.parse(XmlHttp.getResponseHeader("Date"));//获取标头中的时间
offset -= (new Date).getTime(); //获取本地时间与服务器时间的间隔
function ShowTime() //显示时间的方法
{
var d = new Date; //获取当前时间
d.setTime(d.getTime()+offset); //通过服务器和本地的时间间隔获取当前服务器时间
var ddd = new Date();
document.getElementById("webtime").innerHTML=d.format('hh:mm dd/MM/yyyy'); //显示服务器时间
}
setInterval("ShowTime()", "1000");Date.prototype.format = function(format)
{
var o =
{
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format))
format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
for(var k in o)
if(new RegExp("("+ k +")").test(format))
format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
return format;
}
要改成PHP程序.在HTML中显示服务器时间.谢谢各位了.
我现在有一个静态的HTML需求动态的显示服务器时间.服务器可以运行PHP.
想请各位帮忙写一个PHP时间.我在HTML中显示.
我现在用到的是:var XmlHttp;//创建XMLHTTP对象
if(window.XMLHttpRequest) {//表示当前浏览器不是ie,如chrome,firefox
XmlHttp = new XMLHttpRequest();
} else if (window.ActiveXObject) {//表示当前浏览器是IE
XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}XmlHttp.open("HEAD","http://localhost",false);//从哪个服务器上获取时间
XmlHttp.send(); //连接服务器
var offset = Date.parse(XmlHttp.getResponseHeader("Date"));//获取标头中的时间
offset -= (new Date).getTime(); //获取本地时间与服务器时间的间隔
function ShowTime() //显示时间的方法
{
var d = new Date; //获取当前时间
d.setTime(d.getTime()+offset); //通过服务器和本地的时间间隔获取当前服务器时间
var ddd = new Date();
document.getElementById("webtime").innerHTML=d.format('hh:mm dd/MM/yyyy'); //显示服务器时间
}
setInterval("ShowTime()", "1000");Date.prototype.format = function(format)
{
var o =
{
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format))
format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
for(var k in o)
if(new RegExp("("+ k +")").test(format))
format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
return format;
}
要改成PHP程序.在HTML中显示服务器时间.谢谢各位了.
下载链接。
http://www.5y173.com/inc/javascript/jquery.js<!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=utf-8" />
<title>刷服务器时间代码</title>
</head><body>
<script src="/inc/javascript/jquery.js"></script><script>
$(function(){ // DOM文档已经载入就绪
get_time();
});
function get_time()
{
get_server_time();
}
function get_server_time()
{
$.post("/inc/demo/date.php", //这里写php 页面的地址
function(data){
$("#showTime").html("服务器时间为"+data);
}
);
setTimeout(get_server_time,1000);
}
</script>
<div id="showTime"></div>
</body>
</html>
php 页面代码<?php
echo date("Y-m-d H:i:s");
?>