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

PHP輸出時間差函數代碼

php輸出時間差函數

復制代碼 代碼如下:
<?php 
date_default_timezone_set('PRC'); //默認時區 
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 的時候,經常會用到獲取現在之前或之后,某個時間段的日期。現在已經進行收集,大家同時也可以進行擴展豐富
復制代碼 代碼如下:
//獲取當天的星期(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;
}
//獲取現在過幾月的的時間
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;    
}

php技術PHP輸出時間差函數代碼,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 墨竹工卡县| 江川县| 闽清县| 顺昌县| 伊金霍洛旗| 广东省| 达日县| 江华| 仁布县| 敦煌市| 颍上县| 白水县| 保定市| 昌黎县| 启东市| 改则县| 即墨市| 化隆| 裕民县| 泽普县| 宁都县| 视频| 巴东县| 乌兰县| 昆山市| 湖北省| 布尔津县| 项城市| 阿拉尔市| 丹阳市| 鹤庆县| 许昌市| 文山县| 曲周县| 琼中| 阳谷县| 双城市| 新晃| 黄浦区| 马山县| 大埔区|