A PHP/Laravel program of mine collects time dates from an API endpoint, in a variable that I'll call $time. It's presented in the following format:
2018-12-10T22:14:04Z
I want to tidy it up into something more typical, like any of the following:
"10-12-2018"
"22:14, 10-12-2018"
"10-12-2018, 22:14:04"
I'm new to this facet of PHP, so I've been researching different ways to do this. While I've come across some questions similar to mine, and I've found the documentation for tools like createfromformat and strtotime, but from what I've read I don't think they solve for the precise format I'm working with.
Are there any built-in ways in PHP that I can do this? Or any lines of code people might suggest I try to reformat the date as I want to? Any help on this would be greatly appreciated
You can pass your stored datetime string into DateTime() object and freely control format (and more) of it. For example:
$time = '2018-12-10T22:14:04Z';
$dateTimeObject = new \DateTime($time);
echo $dateTimeObject->format('Y-m-d H:i:s'); // will output: 2018-12-10 22:14:04