I have a timestamp that looks like this 2018-09-18T21:49:16Z
from an API. I need to reformat the timestamp to appear in 09-18-2018 @ 21:49:16
. How can I do this in php?
Asked
Active
Viewed 39 times
0

saladCracker
- 69
- 1
- 9
-
1Possible duplicate of [Convert one date format into another in PHP](https://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) – Qirel Sep 19 '18 at 16:23
2 Answers
2
You can do this using DateTime::format()
:
$dateTime = "2018-09-18T21:49:16Z";
$DateTimeFormat = DateTime::createFromFormat("Y-m-d\TH:i:s\Z", $dateTime);
echo $DateTimeFormat->format("m-d-Y @ H:i:s");
// 09-18-2018 @ 21:49:16
You'll have to convert your date and time string (2018-09-18T21:49:16Z
) to a DateTime
object using DateTime::createFromFormate()
.

Tom Udding
- 2,264
- 3
- 20
- 30
0
The PHP datetime suite is your friend.
$mytime = new DateTime('2018-09-18T21:49:16Z');
echo $mytime->format('m-d-Y @ H:i:s');
Which results in:
09-18-2018 @ 21:49:16

Dave
- 5,108
- 16
- 30
- 40