呃..奇怪...但当然,如果你认为这是很重要...
,如果你认为你可以得到JS-时间回从客户端将无法正常工作的尽管PHP脚本仍在运行任何代码!
但是,如果你愿意,你可以通过ajax获取信息。
在这里我们去: 从SQL查询中直接添加一个JavaScript变种增加时间价值的渲染网站的DOM对象 最简单的(你也可以用你只要选择隐藏或甚至可见的DOM对象当你阅读正确的对象值与JavaScript)
为了缓解(对我来说)我假设jQuery的实施。
JavaScript的头
var sqltime = 1360599506; // unix timestamp set by php
// now let's get the information from the user incl his timezone
var tnow = new Date(); // string something like: "Mon Feb 11 2013 17:24:06 GMT+0100"
// and a timestamp-like number for tnow
var tstmp = var now = Math.round(tnow.getTime()/1000)
//and now send those three values via ajax to the server:
var postdata = {action: 'ajaxtime', ts: sqltime, tj: tstmp, tr: tnow};
$.ajax({
type: 'POST',
url: "http://example.com/my.php",
data: postdata,
success: function (response)
{
//do something with the response if you want. just decode the received json string if any
}
});
//you could also compare the two timestamps on clientside if this is more convenient.
,而PHP的应该有一个Ajax请求把这个变成你的php触发,尽可能向上可能(但在此之前得到任何回应或查询到您的SQL!)
if (array_key_exists('ajaxtime', $_REQUEST))
{
$sql time = $_POST['ts'];
$js_timestamp = $_POST['tj'];
$readable_js_time = $_POST['tr'];
// here you can calculate the timestamps and get timezone from the readable_js_time and do whatever you need to.
$json['success'] = true;
$json['result'] = "my result from the calculation";
// make sure no other code of this php is executed because of the ajaxtime request
die();
//if you want to response with a json string to parse in the javascript response use this:
//die (jsonEncode($json));
}
你不这样做,至少不是那样的。 PHP和Javascript不会在相同的环境中运行。你可以用php中的'microtime'来测量执行时间。 – datasage 2013-02-11 15:56:14
你可能是指'new Date()'而不是'new date()'? – Christoph 2013-02-11 15:57:21
所有我想要的是找出一种方法来获得在while循环内的当前时间流逝的时间值。这个怎么做? – coder101 2013-02-11 15:57:29