2019年5月3日 星期五

PHP 日期加減

PHP 日期加減
1. mktime()
$date1 = date ("Y-m-d H:i:s" , mktime(date('H'), date('i'), date('s'), date('m'), date('d')-1, date('Y'))); 
$date2 = date ("Y-m-d H:i:s" , mktime(date('H'), date('i'), date('s'), date('m'), date('d'), date('Y')));
2. strtotime()
$today = '2013-04-19';
echo date("Y-m-d", strtotime($today."+3 year"));
echo date("Y-m-d", strtotime($today."-1 month"));
echo date("Y-m-d", strtotime($today."+10 week"));
echo date("Y-m-d", strtotime($today."+10 day"));
echo date("Y-m-d", strtotime($today."+2 hour"));
echo date("Y-m-d", strtotime($today."+20 minute"));
echo date("Y-m-d", strtotime($today."+5 seconds"));
echo date("Y-m-d", strtotime($today."+1 day 5 seconds"));
echo date("Y-m-d", strtotime($today."+1 week -2 day"));


參考資料 :
http://blog.twbryce.com/strtotime-method/

0 意見:

張貼留言

Popular Posts