如何在 PHP 中将 PHP 时间转换为 Javascript 时间?我的 PHP 代码:
<?php
$times = array(/* A list of time with "Y-m-d h:i:s" format goes here */);
$return = '[';
$i = 1;
foreach($times as $time) {
$return .= '['.strtotime($time).','.$i.'],';
//In my opinion, converting time to
//js time at here is good choice
if($i==100) {
break;
}
$i++;
}
$return = substr($return, 0, -1).']';
?>
我的脚本:
<script>
var results = [{
label: "Buy in",
data: <?=$return?>
}];
</script>
最佳答案
使用 PHP date()
的输出和 Javascript 时间的格式相同,但乘以 1000,因为它具有毫秒分辨率。
关于php - 将 PHP 时间转换为 PHP 中的 Javascript 时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13319226/