从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>

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;
$str = "2014-10-22 07:24:57 EDT";

echo date("M d", strtotime($str)); // Oct 22

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

Try following ( i used date and strtotime ) :

$originalDate = "2014-10-22 07:24:57 EDT";
$newDate = date("M j", strtotime($originalDate));
echo $newDate;