php - 将 PHP 时间转换为 PHP 中的 Javascript 时间

标签 php javascript time

如何在 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/

相关文章:

php - 即使语法正确,INSERT 查询也不起作用

php - 通知 Ajax/Javascript 后台 PHP 已完成

javascript - 使用 php 生成 javascript 代码

php - 避免对某些自动完成的订单重复发送电子邮件通知

javascript - 如何使用 PHP、AJAX 和 AngularJS 创建实时聊天?

javascript - 使用 Javascript 突出显示表格的一行

javascript - 根据单选按钮选择JS显示不同的表id

python - time.clock() 在 Python 中多次?

algorithm - O(n log n) 与 O(log n) 有何不同?

mysql - 计算mysql中面板数据的时间差