首頁  >  文章  >  後端開發  >  php輸出時間差

php輸出時間差

WBOY
WBOY原創
2016-08-08 09:30:531003瀏覽

親測直接使用 strtotime("-1 day");

顯示的是今日的前一日也就是昨日。今天是根據目前的Unix時間截斷來斷定的。

date_default_timezone_set('PRC'); //預設時區
echo "今天:",date("Y-m-d",time()),"
";
echo "今天:",date( "Y-m-d",strtotime("18 june 2008")),"
";
echo "昨天:",date("Y-m-d",strtotime("-1 day")), "
";
echo "明天:",date("Y-m-d",strtotime("+1 day")), "
";
echo "一週後:",date("Y-m-d",strtotime("+1 week") ), "
";
echo "一週零兩天四小時兩秒後:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "
";
echo "下個星期四:",date("Y-m-d",strtotime("next Thursday")), "
";
echo "上個週一:".date("Y-m-d",strtotime("last Monday "))."
";
echo "一個月前:".date("Y-m-d",strtotime("last month"))."
";
echo "一個月後:".date ("Y-m-d",strtotime("+1 month"))."
";
echo "十年後:".date("Y-m-d",strtotime("+10 year"))."
";
?>

//間隔幾分鐘之前或之後的時間
function GetMinute($Minu,$type='l')
{
  if(!strcmp($type,'b')) res=date("Y-m-d H:i:s",strtotime("-$Minu minute"));

else $res=0;

  if(!strcmp($type,'l'))
. date("Y-m-d H:i:s",strtotime("+$Minu minute"));

else $res=0;

  return $res;    
}
//間隔幾秒之前或之後的時間點
func GetSec($sec,$type='l')
{
  if(!strcmp($type,'b'))
     $res=date("Y-m-d H:i:s",strtotime("-$sec second "));

else $res=0;

  if(!strcmp($type,'l'))
     $res=date("Y-m-d H:i:s",strtotime("+$sec second") );

else $res=0;

  return $res;    
}

以上就介紹了php輸出時間差,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn