Home >Backend Development >PHP Problem >What is the time format conversion function in php
The time format conversion functions in php are strtotime and date. For example, to convert the timestamp to [Y-m-d H:i:s], the code is [date("Y-m-d H:i:s",strtotime(' 2020-08-22'));].
The operating environment of this tutorial: windows10 system, php5.4. This article is applicable to all brands of computers.
php time format conversion function: date(), strtotime() function, PHP’s native time class can also convert time format.
(Learning recommendation: php video tutorial)
1. Convert Y-m-d to timestamp
Example: 2017-08-22 Convert to timestamp
strtotime(‘2017-08-22’);
2. Convert timestamp to Y-m-d H:i:s
date("Y-m-d H:i:s",strtotime('2017-08-22'));
3. Convert time Ymd format to Y-m-d
date(“Y-m-d”,strtotime("20170822"));
You can also use native php classes to convert directly
var_dum(\DateTime::createFromFormat('Ymd','20170822')->format('Y-m-d'));
Related recommendations: php training
The above is the detailed content of What is the time format conversion function in php. For more information, please follow other related articles on the PHP Chinese website!