开发者

How do I do this with PHP not Javascript (timestamp conversion)

I have written this Javascript to convert a timestamp to something readable. It works perfectly. However I need to do it with PHP but don't know how. Obviously I don't want an alert of the time, but I'd like to have it as a PHP variable. Any ideas?

<script>
var bmsTime ="39845.03";
var date = new Date('31 dec 1899');
date.setTime(date.getTime() + bmsT开发者_开发知识库ime* 24 * 60 * 60 *1000);

alert (date);
</script>


Use the date function, it takes an additional parameter called timestamp. But in php timestamp is number of seconds, not milliseconds as in javascript, so divide it by 1 000:

echo date('l jS \of F Y h:i:s A', $javascript_timestamp / 1000);


The short answer: You cannot properly do this, as you do not know the timezone the browser/client is using.

Long answer (using the server timezone - or whatever is configured for PHP):

$bmsTime = 39845.03;
$date = mktime(0, 0, 0, 12, 31, 1899);
$date += $bmsTime * 24 * 60 * 60; // $date are the seconds relative to "the epoc" (1970-01-01 UTC)

echo date('c', $date);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜