php強大的時間轉換函數strtotime
更新時間:2016年02月18日 11:55:36 投稿:hebedich
在php中strtotime() 函數將任何英文文本的日期時間描述解析為 Unix 時間戳,這個函數也是我們經常會用到的,有需要的朋友參考一下
使用strtotime可以將各種格式的時間字符串轉換為時間戳
轉換常規(guī)時間格式
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;
完整的php時間描述文檔可以參考 http://php.net/manual/zh/datetime.formats.relative.php
相關文章
淺析php fwrite寫入txt文件的時候用 \r\n不能換行的問題
以下是對php中fwrite寫入txt文件的時候用 \r\n不能換行的問題進行了介紹,需要的朋友可以過來參考下2013-08-08

