php強大的時間轉(zhuǎn)換函數(shù)strtotime
更新時間:2016年02月18日 11:55:36 投稿:hebedich
在php中strtotime() 函數(shù)將任何英文文本的日期時間描述解析為 Unix 時間戳,這個函數(shù)也是我們經(jīng)常會用到的,有需要的朋友參考一下
使用strtotime可以將各種格式的時間字符串轉(zhuǎn)換為時間戳
轉(zhuǎn)換常規(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;
轉(zhuǎn)換自然時間描述
//昨天 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
相關(guān)文章
用PHP實現(xiàn)的四則運算表達式計算實現(xiàn)代碼
題目要求:有一個四則運算的字符串表達式,編寫一個函數(shù),計算四則運算的結(jié)果2011-08-08淺析php fwrite寫入txt文件的時候用 \r\n不能換行的問題
以下是對php中fwrite寫入txt文件的時候用 \r\n不能換行的問題進行了介紹,需要的朋友可以過來參考下2013-08-08