In a 100,000 loop:
date()
= 3.221485 secdate_parse()
= 1.090016 secdate_parse_from_format()
= 0.871224 sec (the fastest!)
سؤال
I have $date_string = '12/1/2014';
I need:
December 1, 2014
I am assuming that using the DateTime class would be the preferred method (and I personally find it very convenient).
// timestamp
$date_string = '12/1/2014'; // input
$d1 = new DateTime($date_string);
$date_timestamp = $d1->getTimestamp(); // output
// re-format
$date_timestamp = '1417410000'; // input
$d2 = new DateTime("@$date_timestamp"); // append @ to hint the timestamp
$date_formatted = $d2->format('F j, Y'); // output
However, I am curious what would be the fastest way to perform both parse operations.
المحلول
In a 100,000 loop:
date()
= 3.221485 secdate_parse()
= 1.090016 secdate_parse_from_format()
= 0.871224 sec (the fastest!)