duanjiaonie6097 2014-10-23 19:54
浏览 40
已采纳

从PHP中的数组更改日期格式[重复]

This question already has an answer here:

I receive a date from an array in the below format:

2014-10-22 07:24:57 EDT

I want to convert this to echo only the month and day like this: Oct 22

My code below works fine when I'm changing from the 15-Feb-2009 format.

<?php

$date = DateTime::createFromFormat('D-M-Y', '15-Feb-2009');
$nice_date = $date->format('M j');

echo $nice_date;

?>

Here's what I have that doesn't work. Probably not even close.

$array_date = '2014-10-22 07:24:57 EDT';
$date = DateTime::createFromFormat('YY-MM-DD HH:II:SS EDT', $array_date);
$nice_date = $date->format('M j');

echo $nice_date;

I'm at a loss right now. Any ideas?

</div>
  • 写回答

4条回答 默认 最新

  • dsns47611 2014-10-23 20:01
    关注

    If you want to explicitly provide the format, you must provide the correct format.

    $array_date = '2014-10-22 07:24:57 EDT';
    $date = DateTime::createFromFormat('Y-m-d H:i:s e', $array_date);
    $nice_date = $date->format('M j');
    echo $nice_date;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?