Home  >  Article  >  Backend Development  >  PHP's powerful time conversion function strtotime_php skills

PHP's powerful time conversion function strtotime_php skills

WBOY
WBOYOriginal
2016-05-16 19:58:171165browse

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn