Php 格式化html表的日期字符串
有人能告诉我如何更改此日期戳并在html表中打印此日期戳吗 我有一个时间戳格式的输入文件:Php 格式化html表的日期字符串,php,html,date-formatting,Php,Html,Date Formatting,有人能告诉我如何更改此日期戳并在html表中打印此日期戳吗 我有一个时间戳格式的输入文件: 4-Start=20100901180002 这个时间格式像这样存储在一个数组中。 我这样打印数组以创建html表: foreach ($data as $row){ $counter ++; $class = $counter % 2 === 0 ? 'alt1' : 'alt2'; ech
4-Start=20100901180002
这个时间格式像这样存储在一个数组中。
我这样打印数组以创建html表:
foreach ($data as $row){
$counter ++;
$class = $counter % 2 === 0 ? 'alt1' : 'alt2';
echo '<tr class="' . $class . '">';
foreach ($keys as $column)
if (isset($row[$column])){
echo '<td>' . $row[$column];
} else {
echo '<td>' . '' . '</td>';
}
}
echo '</table>';
如何将此表中的时间戳更改为此?2010-09-01 18:00:02这就是你要找的, 还有一个类似的问题,你也可以从那里得到更多的信息。。 编辑: 是的,你也可以用它作为回音
echo date("Y-m-d H:i:s",strtotime('20100901180002')) ; // 2010-09-01 18:00:02
正如RC所说,您甚至可以使用CreateFromFormat,这是在过程样式中使用CreateFromFormat
$date = date_create_from_format("YmdHis", '20100901180002');
echo date_format($date, 'Y-m-d H:i:s'); // 2010-09-01 18:00:02
参考这一部分很奇怪,在我看来,这一部分永远也达不到
if (isset($row[$column])){
echo '<td>' . $row[$column] . '</td>';
} elseif ($column == 'Condition') {
echo '<td> Error </td>';
} else {
echo '<td> </td>';
}
我可以把这个函数放在echo语句中动态打印出来吗?好的,谢谢。我只是不知道在哪里使用标签来嵌入它。你可以把数据打印在哪里。例如,我假设这就是您打印数据的方式$行[$column];回响dateY-m-d H:i:s,strotime$行[$列];谢谢你。我清除了该条件,请参见我的编辑。至于格式,我会像在我的foreach中那样在标记中嵌入$date\s吗?再次感谢。不,您需要使用$date->format。。。在你的TD里。注意:对于最近的重复,您的问题-1中现在缺少a。显然没有先搜索。
// PHP > 5.2
$date_s = "" . $row['Start'];
$date = DateTime::createFromFormat("YmdHis", $date_s);
echo $date->format("Y-m-d H:i:s"); // 2010-09-01 18:00:02