I need to set a dateTime in this specific date format:
2016-10-19T11:06:20.000+00:00
So I found that this one work:
'date'=> $dateStart->format('Y-m-d\Th:m:s')
this is from a array cell setting inside a loop. At the first level of an multi level array.
Before this set, $dateStart
is treathed like that:
$dateStart = new DateTime();
$dateStart->setTimeStamp($inputs['extraData']['dataStart']/1000);
And the var $inputs['extraData']['dataStart']
contain an UnixTimeStamp as this one:
1493828407000
All the time stamp are correct in the right ascending order. In a next level of the same array I try to set another timestamp in this way:
$timeStamp=$cellaViaggio['timestamp'];
$date3= new DateTime();
$date3->setTimestamp($timeStamp/1000)->format('Y-m-d\Th:m:s');
then inside the array
array('name'=>'TIMESTAMP','value'=>$date3)
then this array is used as soap Data envelope in a call made by PHP Soap client.
If I leave all like that my Laravel rise an error of:
ErrorException in TripController.php line 37: Object of class DateTime could not be converted to string
Otherwise if I leave all like that but I move the format command ( ->format('Y-m-d\Th:m:s') )
inside the array cell writing like that:
array('name'=>'TIMESTAMP','value'=>$date3->format('Y-m-d\Th:m:s'))
this no raise any error but the timestamp is wrong, because the minutes will not change and just second are increased at every loop, but not the minutes! So something like about the time:
00:01:30
00:01:40
00:01:59
00:01:33
oo:01:03
As I said we talk about progressive timestamp.
Keep in mind that the timestamp is assigned to an Array of Array of Array to keep the soap envelope in the right format for the server.
this is the code for the SOAP client:
$client = new \SoapClient("http://soapserviceserver.xx/services/spPushDataServicePort?wsdl");
try {
return $cli->pushData($param);
} catch (SoapFault $e) {
return $e->getMessage();
}
$params
contains the array set as described above.
The format is not proper because you are using
$date3->format('Y-m-d\Th:m:s')
Instead you should use
$date3->format('Y-m-d\Th:i:s')
Here is an example
\Carbon\Carbon::now()->format('Y-m-d\Th:i:s')
Result
2017-06-13T06:44:45
result after some time 2017-06-13T06:45:24
Read more about PHP Date formats here
i : Minutes with leading zeros
If you want perfect Date format according to the example given in the question then you can use
date(DATE_ATOM)
Result 2017-06-13T18:51:08+05:30