Home > Article > Backend Development > PHP's powerful time conversion function strtotime_php skills
Use strtotime to convert time strings in various formats into timestamps
Convert regular time format
echo date('Y-m-d H:i:s', strtotime('2016-01-30 18:00')).PHP_EOL; echo date('Y-m-d H:i:s', strtotime('20160130180001')).PHP_EOL;
Convert natural time description
//昨天 echo date('Y-m-d H:i:s', strtotime('yesterday')).PHP_EOL; //上周 echo date('Y-m-d H:i:s', strtotime('last week')).PHP_EOL; //本周开始时间 echo date('Y-m-d H:i:s', strtotime('this week midnight')).PHP_EOL; //本月开始时间 echo date('Y-m-d H:i:s', strtotime('first day of this month midnight')).PHP_EOL; //计算相对时间 echo date('Y-m-d H:i:s', strtotime('+1 month')).PHP_EOL;
For the complete php time description document, please refer to http://php.net/manual/zh/datetime.formats.relative.php