使用strtotime可以將各種格式的時(shí)間字符串轉(zhuǎn)換為時(shí)間戳
轉(zhuǎn)換常規(guī)時(shí)間格式
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;
轉(zhuǎn)換自然時(shí)間描述
//昨天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;//本周開(kāi)始時(shí)間echo date('Y-m-d H:i:s', strtotime('this week midnight')).PHP_EOL;//本月開(kāi)始時(shí)間echo date('Y-m-d H:i:s', strtotime('first day of this month midnight')).PHP_EOL; //計(jì)算相對(duì)時(shí)間echo date('Y-m-d H:i:s', strtotime('+1 month')).PHP_EOL;
完整的php時(shí)間描述文檔可以參考 http://php.net/manual/zh/datetime.formats.relative.php