How do I convert the following string:
24 May, 2012, 00:00am
to a format like:
$today = date("D M j G:i:s T Y"); // Sat Mar 10 17:16:18 MST 2001
I’ve tried the following:
$date = date('D M j G:i:s T Y', strtotime("24 May, 2012, 00:00am"));
But all I get is:
Thu Jan 1 0:00:00 UTC 1970
I’m considering exploding the string and then running it through mktime() but I am wondering if there is a better way to do this?
I would use the
DateTimeclass and thecreateFromFormatfunction, which allows you to parse a date according to a format that you define.In this case:
You can then use the other DateTime functions to manipulate this.
Note that the date you provide is in fact incorrect by any standard: you either mean
00:00or12:00am.