You are almost there. You have used 'Z' where you should have a 'u' for microseconds, so your code should look something like this:-
$dateStr = '2011-11-09T17:11:57.430+05:00';
$date = \DateTime::createFromFormat('Y-m-d\TH:i:s.uP', $dateStr);
var_dump($date);
Output:-
object(DateTime)[1]
public 'date' => string '2011-11-09 17:11:57' (length=19)
public 'timezone_type' => int 1
public 'timezone' => string '+05:00' (length=6)
The format strings accepted by DateTime::createFromFormat()
are the same as those accepted by date()
.