php強大的時間轉換函數strtotime

在php中strtotime() 函數將任何英文文本的日期時間描述解析爲 Unix 時間戳,這個函數也是我們經常會用到的`,有需要的朋友參考一下.

php強大的時間轉換函數strtotime

使用strtotime可以將各種格式的時間字符串轉換爲時間戳

  轉換常規時間格式

?

1

2

3

echo date('Y-m-d H:i:s', strtotime('2016-01-30 18:00'))_EOL;

echo date('Y-m-d H:i:s', strtotime('20160130180001'))_EOL;

轉換自然時間描述

//昨天

echo date('Y-m-d H:i:s', strtotime('yesterday'))_EOL;

//上週

echo date('Y-m-d H:i:s', strtotime('last week'))_EOL;

//本週開始時間

echo date('Y-m-d H:i:s', strtotime('this week midnight'))_EOL;

//本月開始時間

echo date('Y-m-d H:i:s', strtotime('first day of this month midnight'))_EOL;

//計算相對時間

echo date('Y-m-d H:i:s', strtotime('+1 month'))_EOL;