色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

PHP輸出時(shí)間差函數(shù)代碼

php輸出時(shí)間差函數(shù)

復(fù)制代碼 代碼如下:
<?php 
date_default_timezone_set('PRC'); //默認(rèn)時(shí)區(qū) 
echo "今天:",date("Y-m-d",time()),"<br>"; 
echo "今天:",date("Y-m-d",strtotime("18 june 2008")),"<br>"; 
echo "昨天:",date("Y-m-d",strtotime("-1 day")), "<br>"; 
echo "明天:",date("Y-m-d",strtotime("+1 day")), "<br>"; 
echo "一周后:",date("Y-m-d",strtotime("+1 week")), "<br>"; 
echo "一周零兩天四小時(shí)兩秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "<br>"; 
echo "下個(gè)星期四:",date("Y-m-d",strtotime("next Thursday")), "<br>"; 
echo "上個(gè)周一:".date("Y-m-d",strtotime("last Monday"))."<br>"; 
echo "一個(gè)月前:".date("Y-m-d",strtotime("last month"))."<br>"; 
echo "一個(gè)月后:".date("Y-m-d",strtotime("+1 month"))."<br>"; 
echo "十年后:".date("Y-m-d",strtotime("+10 year"))."<br>"; 
?>

在學(xué)習(xí)php 的時(shí)候,經(jīng)常會(huì)用到獲取現(xiàn)在之前或之后,某個(gè)時(shí)間段的日期?,F(xiàn)在已經(jīng)進(jìn)行收集,大家同時(shí)也可以進(jìn)行擴(kuò)展豐富
復(fù)制代碼 代碼如下:
//獲取當(dāng)天的星期(1-7)
function GetWeek($times)
{
    $res = date('w', strtotime($times));
    if($res==0)
       $res=7;
    return $res;
}
//獲取當(dāng)天時(shí)間
function GetTime($times)
{
    $res = date('H:i', strtotime($times));
    return $res;
}
//獲取現(xiàn)在過幾月的的時(shí)間
function GetMonth($Month,$type='l')
{
    if(!strcmp($type,'b'))
      $res=date("Y-m-d H:i:s",strtotime("-$Month months"));
    if(!strcmp($type,'l'))
      $res=date("Y-m-d H:i:s",strtotime("+$Month months"));
    return $res;
}
//獲取當(dāng)前時(shí)間
function GetCurrentDateTime()
{
    $res=date("Y-m-d H:i:s",time());
    return $res;
}
//獲取當(dāng)前時(shí)間隔幾小時(shí)之前或之后的時(shí)間
function GetDiffHours($hours,$type='l')
{
  if(!strcmp($type,'b'))
     $res=date("Y-m-d H:i:s",strtotime("-$hours hour"));
  if(!strcmp($type,'l'))
     $res=date("Y-m-d H:i:s",strtotime("+$hours hour"));
  return $res;    
}
//間隔幾分鐘之前或之后的時(shí)間
function GetDiffMinute($Minute,$type='l')
{
  if(!strcmp($type,'b'))
     $res=date("Y-m-d H:i:s",strtotime("-$Minute minute"));
  if(!strcmp($type,'l'))
     $res=date("Y-m-d H:i:s",strtotime("+$Minute minute"));
  return $res;    
}
//間隔幾秒之前或之后的時(shí)間
function GetDiffSec($sec,$type='l')
{
  if(!strcmp($type,'b'))
     $res=date("Y-m-d H:i:s",strtotime("-$sec second"));
  if(!strcmp($type,'l'))
     $res=date("Y-m-d H:i:s",strtotime("+$sec second"));
  return $res;    
}

//間隔幾個(gè)星期之前或之后的時(shí)間
function GetDiffWeek($Week,$type='l')
{
  if(!strcmp($type,'b'))
     $res=date("Y-m-d H:i:s",strtotime("-$Week week"));
  if(!strcmp($type,'l'))
     $res=date("Y-m-d H:i:s",strtotime("+$Week week"));
  return $res;    
}
// 間隔幾天之間的時(shí)間
function GetDiffDays($days,$type='l')
{
  if(!strcmp($type,'b'))
     $res=date("Y-m-d H:i:s",strtotime("-$days day"));
  if(!strcmp($type,'l'))
     $res=date("Y-m-d H:i:s",strtotime("+$days day"));
  return $res;    
}
//間隔幾年之前或之后的時(shí)間
function GetDiffYears($year,$type='l')
{
  if(!strcmp($type,'b'))
     $res=date("Y-m-d H:i:s",strtotime("-$year year"));
  if(!strcmp($type,'l'))
     $res=date("Y-m-d H:i:s",strtotime("+$year year"));
  return $res;    
}

php技術(shù)PHP輸出時(shí)間差函數(shù)代碼,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 虹口区| 珠海市| 从化市| 远安县| 安平县| 观塘区| 保靖县| 新密市| 苗栗市| 浦北县| 定边县| 什邡市| 静海县| 垣曲县| 周宁县| 陆丰市| 洛浦县| 遵化市| 南安市| 江永县| 华蓥市| 特克斯县| 汾阳市| 台中市| 竹北市| 孝昌县| 株洲县| 隆化县| 牟定县| 通州市| 洛南县| 南皮县| 林州市| 林周县| 城步| 全椒县| 永州市| 上栗县| 章丘市| 定襄县| 始兴县|