0

我有一个包含完整日期和时间值的数组:

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]

4

2 回答 2

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']));
}
于 2012-12-13T07:49:25.120 回答
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;
}

有关更多信息,请访问此链接:DateTime 类

于 2012-12-13T07:59:01.793 回答