显示带有用户输入日期的PHP时钟 [英] Display PHP Clock with user input date

查看:46
本文介绍了显示带有用户输入日期的PHP时钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下PHP代码显示带有当前日期和时间的时钟。



我希望时钟接收用户输入日期。



如何做到这一点?



date_default_timezone_set(Asia / Kolkata);

if(@ $ _ GET [action] ==getTime){

$ time1 = Time();



$ date1 = date(m / d / Y h:i:s A,$ time1);

// echo $ date1; // ajax请求的时间输出



$ aa = explode(,$ date1);

// echo;

echoDate:。$ aa [0];

echo;

echo时间:。$ aa [1] ;

die();





}

?>



The following PHP code displays a clock with current date and time.

I want the clock to receive user input date.

How can this be done?

date_default_timezone_set("Asia/Kolkata");
if(@$_GET["action"]=="getTime"){
$time1 = Time();

$date1 = date("m/d/Y h:i:s A",$time1);
//echo $date1; // time output for ajax request

$aa=explode(" ",$date1);
//echo "";
echo "Date: ".$aa[0];
echo "";
echo "Time: " .$aa[1];
die();


}
?>





< script type =text / javascript>

window.onload = startInterval;

函数startInterval(){

setInterval(startTime();,1000);

}

函数startTime(){

AX =新ajaxObject(?action = getTime,showTime)

AX.update(); //启动Ajax请求

}

// CallBack

函数showTime(数据){

document.getElementById ('qwe')。innerHTML = data;

}

< / script>







< script type =text / javascript>

// Ajax对象 - 构造函数

函数ajaxObject(url,callbackFunction){

var that = this;

this.updating = false ;

this.abort = function(){

if(that.updating){

that.updating = false;

that.AJAX.abort();

that.AJAX = null;

}

};

this.update =

函数(passData,postMethod){

if(that.updating){return false; }

that.AJAX = null;

if(window.XMLHttpRequest){

that.AJAX = new XMLHttpRequest();

} else {

that.AJAX = new ActiveXObject(Microsoft.XMLHTTP);

}

if(that .AJAX == null){

返回false;

} else {

that.AJAX.onreadystatechange = function(){

if(that.AJAX.readyState == 4){

that.updating = false;

that.callback(that.AJAX.responseText,that .AJAX.status,that.AJAX.responseXML,that.AJAX.getAllResponseHeaders());

that.AJAX = null;

}

};

// var dt =;

that.updating = new Date();

if(/post/i.test(postMethod)){

var uri = urlCall + (/\?/ i.test(urlCall)?'&':'?')+'timestamp ='+ that.updating.getTime();

that.AJAX.open( POST,uri,true);

that.AJAX.setRequestHeader(Content-type,application / x-www-form-urlencoded);

that.AJAX.setRequestHeader(Content-Length,passData.length);

that.AJAX.send(passData);

} else {

var uri = urlCall +(/ \?/i.test(urlCall)?'&':'?')+ passData +'×tamp ='+(that.updating.getTime());

that.AJAX.open(GET,uri,true);

that.AJAX.send(null);

}

返回true;

}

};

var urlCall = url;

this.callback = callbackFunction || function(){};

}

< / script>



<script type="text/javascript">
window.onload = startInterval;
function startInterval() {
setInterval("startTime();",1000);
}
function startTime() {
AX = new ajaxObject("?action=getTime", showTime)
AX.update(); // start Ajax Request
}
// CallBack
function showTime( data ){
document.getElementById('qwe').innerHTML = data;
}
</script>



<script type="text/javascript">
// Ajax Object - Constructor
function ajaxObject(url, callbackFunction) {
var that=this;
this.updating = false;
this.abort = function() {
if (that.updating) {
that.updating=false;
that.AJAX.abort();
that.AJAX=null;
}
};
this.update =
function(passData,postMethod) {
if (that.updating) { return false; }
that.AJAX = null;
if (window.XMLHttpRequest) {
that.AJAX=new XMLHttpRequest();
}else{
that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
}
if (that.AJAX==null) {
return false;
}else{
that.AJAX.onreadystatechange = function() {
if (that.AJAX.readyState==4) {
that.updating=false;
that.callback( that.AJAX.responseText, that.AJAX.status, that.AJAX.responseXML, that.AJAX.getAllResponseHeaders() );
that.AJAX=null;
}
};
//var dt= ;
that.updating = new Date();
if (/post/i.test(postMethod)) {
var uri=urlCall+(/\?/i.test(urlCall)?'&':'?')+'timestamp='+that.updating.getTime();
that.AJAX.open("POST", uri, true);
that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
that.AJAX.setRequestHeader("Content-Length", passData.length);
that.AJAX.send(passData);
}else{
var uri=urlCall+(/\?/i.test(urlCall)?'&':'?')+passData+'×tamp='+(that.updating.getTime());
that.AJAX.open("GET", uri, true);
that.AJAX.send(null);
}
return true;
}
};
var urlCall = url;
this.callback = callbackFunction || function (){};
}
</script>

推荐答案

_GET [action ] ==getTime){
_GET["action"]=="getTime"){


time1 = Time();


time1 = Time();


date1 = date(m / d / Y h:i:s A,
date1 = date("m/d/Y h:i:s A",


这篇关于显示带有用户输入日期的PHP时钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆