1

I'm working with an API that returns timestamps in this format:

07/23/2017 23:39:21

The format is: MM/DD/YYYY HH:MM:SS

I need to covert this string so it displays in this format on my webpage:

23 July 2017, 11:39pm

Is this possible?

user982124
  • 4,416
  • 16
  • 65
  • 140

2 Answers2

1

You can do this :

$date = new DateTime('07/23/2017 23:39:21');
echo $date->format('d F o, h:ia');

Output :

23 July 2017, 11:39pm

Baptiste
  • 1,688
  • 1
  • 15
  • 25
0

Take a look at http://php.net/manual/de/datetime.createfromformat.php. You'll get a DateTime object which you can convert in the format you desire.

Like so:

<?php
$date = DateTime::createFromFormat('m/d/Y H:i:s', '07/23/2017 23:39:21');
echo $date->format('d M Y, h:ia');
?>