我必须创建一个包含每行日期/时间的数组。 我正在使用以下代码。 “TIME_STAMP”是包含 MySQL 时间戳的字段(默认为 CURRENT_TIMESTAMP)。
while ( $row = mysql_fetch_array($result) )
{
$timestamp = strtotime($row["TIME_STAMP"]);
$x[] = sprintf("%s, %s", date ('j/n', $timestamp), date('H:i', $timestamp));
}
如果我从 mysql 客户端进行 SELECT * 一切正常:时间戳是正确的:
2013-06-04 17:11:43
但是当我将此数组传递给 JpGraph (以制作水平轴)时,所有记录都显示为
1月1日 01:00
图表代码:
$graph = new Graph("1024", "800");
$graph->SetScale( 'textlin');
$graph->img-> SetMargin(60,40,40,110);
$graph->xaxis->SetTickLabels( $x );
$graph->xgrid->Show(true);
有什么提示吗?
最佳答案
我的猜测是您正在处理的值是一个字符串,而不是实际的 DateTime 对象。在将其传递到下一步之前,您可能需要使用该字符串创建一个新的 DateTime 对象。
关于php - MySQL 时间戳到日期/时间 PHP : always 1/1/1 01:00,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16922134/