将奇怪的格式化时间戳分成可理解的日期

I'm working with an XML document that is returning variables and for some reason in a xml return the timestamp is formatted like this... 20180606T110000 ... why anyone would format it like that makes no sense to me; however, its what I have to work with. ITs formatted YYYYMMDD , the T is the split between date and time, HHMMSS. ITs set up in a 24 Hour clock that I also need to convert to 12 hr clock with am/pm

I need that formatted like 06/06/2018 11:00:00 AM.

Is there a way to do that via a date format (I know how to use date() but I don't know how to bring in that timestamp the way its formatted) or even separating it out into

$year = xxxx 
$month = xx 
$day = $xx 
$Hour=xx 
etc. etc. etc. 

if need be.

I've briefly looked at php's date create from format ( date_create_from_format('j-M-Y', '15-Feb-2009') ) but dont fully understand how that works.

I've also thought about a split. I've also looked at chunk_split and wordwrap but its not even amounts of characters so that would be complex to create.

Any ideas?

The format you're working with is "XMLRPC (Compact)" format. This is fully supported by PHP (you can see a list of supported formats here). To get what you want, just use a combination of strtotime() and date().

$timestring = "20180606T110000";

$timestamp = strtotime($timestring);

echo date("m/d/Y h:i:s A", $timestamp);

You can use PHP DateTime to parse a datetime String with any format. Please view the Parameters format in the following link to understand how the "Ymd\THis" part works: http://php.net/manual/en/datetime.createfromformat.php

<?php

$time = "20180606T110000";

$date = DateTime::createFromFormat("Ymd\THis", $time);

// 06/06/2018 11:00:00 AM.
echo $date->format("d/m/Y h:i:s A");