我有从数据库返回这个的 php 代码,
[
{
"Time": "2012-11-27 16:10:35",
"NumPlayers": "1"
},
{
"Time": "2012-11-27 16:24:55",
"NumPlayers": "1"
},
{
"Time": "2012-11-27 16:25:37",
"NumPlayers": "2"
},
{
"Time": "2012-11-27 16:29:33",
"NumPlayers": "2"
时间是 MySQL 时间戳。我需要把它变成这种格式才能与 Highcharts javascript 图表一起使用。
data: [
[Date.UTC(1970, 9, 9), 0 ],
[Date.UTC(1970, 9, 14), 0.15],
[Date.UTC(1970, 10, 28), 0.35],
[Date.UTC(1970, 11, 12), 0.46],
我无法弄清楚如何遍历 MySQL 结果并将时间戳转换为 javascript Date.UTC 对象。我需要将 NumPlayers 值放在 Date.UTC 对象之后,并以下面的格式输出。我是 PHP 和 javascript 菜鸟:\
它应该看起来像这样:
data: [
[Date.UTC(2012, 11, 27, 16, 10, 35), 1],
[Date.UTC(2012, 11, 27, 16, 24, 55), 1],
[Date.UTC(2012, 11, 27, 16, 25, 37), 2],
[Date.UTC(2012, 11, 27, 16, 29, 33), 2],