PHP 日期加減



$timeString = '2015-12-16'; // Y-m-d G:i:s;



// 加5年

echo date('Y-m-d G:i:s', strtotime($timeString."+5 year"));

// 2020-12-16 0:00:00



// 加7個月

echo date('Y-m-d G:i:s', strtotime($timeString."+7 month"));

// 2016-07-16 0:00:00



// 減1天

echo date('Y-m-d G:i:s', strtotime($timeString."-1 day"));

// 2015-12-15 0:00:00



// 減3週

echo date('Y-m-d G:i:s', strtotime($timeString."-3 week"));

// 2015-11-25 0:00:00



// 加5小時

echo date('Y-m-d G:i:s', strtotime($timeString."+5 hour"));

// 2015-12-16 5:00:00



// 加7分鐘

echo date('Y-m-d G:i:s', strtotime($timeString."+7 minute"));

// 2015-12-16 0:07:00



// 減3秒

echo date('Y-m-d G:i:s', strtotime($timeString."-3 seconds"));

// 2015-12-15 23:59:57








留言

這個網誌中的熱門文章

成人剪舌繫帶聽過嗎?我剪了!!

Scp - ssh 的遠端檔案傳輸指令

睡覺使你更有效率