PHP: parsing the default format in the default postgre format

Am I having a problem parsing the next two lines of a time stamp?

$timestamp1 = "2013-10-15 19:05:18.756932+03";
$timestamp2 = "2013-10-15 19:05:18.756932+03:00";

I have it so far, but he is returning with false

$datetime = DateTime::createFromFormat('Y-m-d HH:MM:SS frac "GMT"? [+-] hh ":"? MM?', $timestamp1);
$datetime = DateTime::createFromFormat('Y-m-d HH:MM:SS frac "GMT"? [+-] hh ":"? MM?', $timestamp2);

What happened? Thanks.

PS I tried this 'Y-m-d HH:MM:SSfrac"GMT"?[+-]hh":"?MM?', this ''Y-m-d HH:MM:SS[0-9]+"GMT"?[+-]hh":"?MM?'and this 'Y-m-d HH:MM:SS [0-9] "GMT"? [+-] hh ":"? MM?', but it always fails.

+4
source share
2 answers

Assuming the last part is a time zone offset, Y-m-d H:i:s.ueshould work.

If this is the default format by default, you probably have to handle the case where there are no fractional seconds ( 2013-10-15 19:05:18+03) s Y-m-d H:i:se.

+5
source

You have an error in your format string.

$datetime = DateTime::createFromFormat('Y-m-d H:i:s.uP', $timestamp1);

: PHP: DateTime:: createFromFormat

+2

All Articles