Home > Article > Backend Development > How to implement time format conversion in php
How to implement time format conversion in php: You can use the date() function and strtotime() function to implement time format conversion, such as [date("Y-m-d H:i:s",strtotime('2017-08 -twenty two'));】.
The PHP time format conversion functions include date() and strtotime() functions. PHP’s native time class can also convert time formats.
(Recommended tutorial: 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"));
Can also be converted directly using native php classes
var_dum(\DateTime::createFromFormat('Ymd','20170822')->format('Y-m-d'));
4. Get the current timestamp:
time();
or
date('U');
5. Tomorrow’s time format
date("Y-m-d H:i:s",strtotime(+1 day));
Related recommendations: php training
The above is the detailed content of How to implement time format conversion in php. For more information, please follow other related articles on the PHP Chinese website!