Failed to parse time string zulu time - Hack The Tech - Latest News related to Computer and Technology

logo

Get Daily Latest News related to Computer and Technology and hack the world.

Wednesday, June 2, 2021

demo-image

Failed to parse time string zulu time

when trying to parse a date-time (Zulu) with Carbon, I get the following error:

$t = '2021-06-01T21:29:55.155257426Z';
$r = Carbon::parse($t)->setTimezone('UTC');
dd($r);
Could not parse '2021-06-01T21:29:55.155257426Z': DateTime::__construct(): Failed to parse time string (2021-06-01T21:29:55.155257426Z) at position 0 (2): The timezone could not be found in the database

However, if I remove the last 3 digits, everything works fine, e.g.:

$t = '2021-06-01T21:29:55.155257Z';
$r = Carbon::parse($t)->toDateTimeString('microsecond');
dd($r);
"2021-06-01 21:29:55.155257"

I'm not sure what to do to parse the microseconds when I have 9 digits (.155257426Z). Any help is appreciated. Thank you.



source https://stackoverflow.com/questions/67797075/failed-to-parse-time-string-zulu-time

No comments:

Post a Comment