我有一个包含完整日期和值的数组。时间:
Array
(
[0] => Array
(
[name] => Jammy
[date] => 2012-12-12 09:47:07
[id] => 151
)
[1] => Array
(
[name] => Kathy
[date] => 2012-12-11 09:48:43
[id] => 152
)
所以,如果我想要打印如下,我该怎么办? 样本输出:
Jammy加入[日期:2012年12月12日,时间:09:48]
答案 0 :(得分:5)
foreach ($arr as $value) {
echo $value['name'].' joined on [ Date: '.date('d M Y',strtotime($value['date'])).' , Time:'.date('H:i',strtotime($value['date']));
}
答案 1 :(得分:2)
试试这个
foreach ($array as $value) {
$time = new DateTime($value['date']);
$date = $time->format('d M Y');
$time = $time->format('H:i');
echo $value['name'].' joined on [ Date: '.$date.' , Time:'.$time;
}
有关详情,请访问以下链接:The DateTime class