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/

Related Posts:

  • Strict Standards: Only variables should be passed by reference in 升級 PHP 後 會遇到錯誤回報 Strict Standards: Only variables should be passed by reference in  $SQL->bindParam(':page', getenv('REQUEST_URI')); 看到這報錯後,我變更改成以下 $temp = getenv('REQUEST_URI'); $SQL-bindParam(':page', $temp);… Read More
  • PHP Function with Optional ParametersPHP Function with Optional Parameters 有 2 種方法 1. 用 NULL arguments function method($arg1 = null, $arg2 = null){ $arg1 = $arg1? $arg1: "default_value_for_arg1"; $arg2 = $arg2? $arg2: "default_value_for_arg2"; } 2. 傳 Array… Read More
  • 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'), da… Read More

0 意見:

張貼留言

Popular Posts