What method should I use to convert 2021-03-20T00:19:07.000000Z to 2021-03-20 00:19:07, in PHP and Laravel 8.x, by the way, If you can explain what does the T in the middle of 2021-03-20T00:19:07.000000Z and the dot behind each represent? I will very much appreciate you !!
Asked
Active
Viewed 286 times
0
-
1It's called "zulu time". See https://stackoverflow.com/questions/8405087 and https://stackoverflow.com/questions/44206123 and https://stackoverflow.com/questions/12181457 – Syscall Apr 20 '21 at 07:02
2 Answers
1
You can use Carbon date library in php and laravel.
Carbon::parse('2021-03-20T00:19:07.000000Z')->format('Y-m-d H:i:s')

Jaswinder Singh
- 731
- 5
- 20
0
Your input date is an ISO 8601 formatted date.
The T
is the divider between date and time, so it is a static value.
To convert your ISO 8601 date to a YYYY-MM-DD hh:mm:ss
date format, you can easily use DateTime
(DateTime Documentation).
So in your case the solution would be:
$input = '2021-03-20T00:19:07.000000Z';
$datetime = new DateTime(input);
$output = $datetime->format('Y-m-d H:i:s');

Roman
- 2,530
- 2
- 27
- 50