使用strtotime可以將各種格式的時間字符串轉換為時間戳
轉換常規時間格式:
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;
轉換自然時間描述:
- //昨天
- 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;
新聞熱點
疑難解答