format('jS, F Y')"."/> format('jS, F Y')".">
Home > Article > Backend Development > How to convert php datetime to string
How to convert php date and time to string: 1. Create a PHP sample file; 2. New a DateTime; 3. Use "$datetime->format('jS, F Y')" to Just convert the date and time into a string.
The operating environment of this article: Windows7 system, PHP7.1 version, Dell G3 computer
How to convert php date and time for string?
PHP uses the DateTime class to convert time and date to string
PHP’s processing of time and date is not very standardized. It’s simple. It’s just that I don’t know whether the input string can be Correctly converted to the required DateTime type.
Object-oriented PHP should use the DateTime class to convert string and dateTime
From string to time type
DateTime::createFromFormat(‘m/d/Y H:i','03/01/2008 02:20'); $totalPrice=0.0;
From DateTime to string
$datetime = new DateTime('2008-08-03 14:52:10'); echo $datetime->format('jS, F Y') . "/n";
Get the current time
getdate()
Although this operation is a bit troublesome, each part is in a format that is precisely controlled by myself, so I feel more at ease.
The above are only for PHP 5.3 and above
Old versions still need to use this
echo date('m/d/Y H:i',strtotime('10/20/2009 15:21'));
Note: What is read from the database using an array is a character type
Recommended: "PHP Video Tutorial"
The above is the detailed content of How to convert php datetime to string. For more information, please follow other related articles on the PHP Chinese website!