I have problem to parse the following two time-stamp strings in a generic way?
$timestamp1 = "2013-10-15 19:05:18.756932+03";
$timestamp2 = "2013-10-15 19:05:18.756932+03:00";
I have this so far but it returns 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's wrong? Thank you.
P.S. 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.
Assuming the last part is a timezone offset, Y-m-d H:i:s.ue
should work.
If this is posgre's default format you will probably need to handle the case when there are no fractional seconds (2013-10-15 19:05:18+03
) with Y-m-d H:i:se
.
You have an error in your format string.
$datetime = DateTime::createFromFormat('Y-m-d H:i:s.uP', $timestamp1);
Here is the documentation for the format string options: PHP: DateTime::createFromFormat Manual
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With