format a date in to the format october 13, 2014 11:13:00.000 am in php

You can use the DateTime class along with the format() method to achieve this format. Here's an example code block:

main.php
$date = new DateTime('2014-10-13 11:13:00.000');
$formatted_date = $date->format('F d, Y h:i:s.u A');
echo $formatted_date;
124 chars
4 lines

This code will output October 13, 2014 11:13:00.000 AM.

Explanation:

  • First, we create a DateTime object using the input date string.
  • Then, we call the format() method on the object with the desired format string as the argument.
  • In the format string, F represents the full textual month name, d represents the day of the month, Y represents the year, h represents the hour (12-hour format), i represents the minutes, s represents the seconds, u represents the microseconds, and A represents the AM/PM indicator in uppercase.

gistlibby LogSnag