最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2013年01月28日 12:18:40   作者:  
在學習PHP 的時候,經(jīng)常會用到獲取現(xiàn)在之前或之后,某個時間段的日期?,F(xiàn)在已經(jīng)進行收集,大家同時也可以進行擴展豐富

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

復制代碼 代碼如下:

<?php 
date_default_timezone_set('PRC'); //默認時區(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 "一周零兩天四小時兩秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "<br>"; 
echo "下個星期四:",date("Y-m-d",strtotime("next Thursday")), "<br>"; 
echo "上個周一:".date("Y-m-d",strtotime("last Monday"))."<br>"; 
echo "一個月前:".date("Y-m-d",strtotime("last month"))."<br>"; 
echo "一個月后:".date("Y-m-d",strtotime("+1 month"))."<br>"; 
echo "十年后:".date("Y-m-d",strtotime("+10 year"))."<br>"; 
?>

在學習PHP 的時候,經(jīng)常會用到獲取現(xiàn)在之前或之后,某個時間段的日期。現(xiàn)在已經(jīng)進行收集,大家同時也可以進行擴展豐富
復制代碼 代碼如下:

//獲取當天的星期(1-7)
function GetWeek($times)
{
    $res = date('w', strtotime($times));
    if($res==0)
       $res=7;
    return $res;
}
//獲取當天時間
function GetTime($times)
{
    $res = date('H:i', strtotime($times));
    return $res;
}
//獲取現(xiàn)在過幾月的的時間
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;
}
//獲取當前時間
function GetCurrentDateTime()
{
    $res=date("Y-m-d H:i:s",time());
    return $res;
}
//獲取當前時間隔幾小時之前或之后的時間
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;    
}
//間隔幾分鐘之前或之后的時間
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;    
}
//間隔幾秒之前或之后的時間
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;    
}

//間隔幾個星期之前或之后的時間
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;    
}
// 間隔幾天之間的時間
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;    
}
//間隔幾年之前或之后的時間
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;    
}

相關文章

最新評論

高陵县| 新蔡县| 赫章县| 黄骅市| 南城县| 荔浦县| 磐安县| 宜宾县| 鹤岗市| 陈巴尔虎旗| 玛沁县| 南通市| 宁海县| 建瓯市| 丰镇市| 瑞金市| 彰武县| 明水县| 姜堰市| 邳州市| 天水市| 辽阳县| 景洪市| 广昌县| 尼勒克县| 乌兰察布市| 潜江市| 诸暨市| 柞水县| 红安县| 航空| 凯里市| 鸡西市| 富源县| 临颍县| 昌江| 武城县| 邯郸市| 郧西县| 澄城县| 滨海县|