[SalesForce] Date format with Salesforce REST API

I'm retrieving the "LastModifiedDate" attribute of a File through a GET request with the Salesforce REST API but I just can't figure out the date format.

Salesforce's documentation states the date format is ISO8601 but when I do the following in PHP :

// The value I retrieve is "2014-11-20T14:23:44.000+0000"
$date = \Datetime::createFromFormat(\Datetime::ISO8601, [value]);

PHP throws an error saying it couldn't create a date with this format and this value.

Do you know what is the actual date format used by Salesforce in its REST API ?

Thanks for your answers.

Cheers.

Best Answer

According to the documentation here http://php.net/manual/en/datetime.createfromformat.php you can try this

<?php
    $value = "2014-11-20T14:23:44.000+0000"; // example value
    $value = substr($value,0,19);
    $date = new DateTime();
    $date = DateTime::createFromFormat('Y-m-d?H:i:s', $value);
    print( "TEST<br> ".$value ."<br>" ); 
    print_r( $date );    
?>

To respect the timezone, you need a bit more string cutting. It looks like the milliseconds needs to be removed an the offset need a ":" inbetween. Look for the string functions here http://php.net/manual/en/book.strings.php