欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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)在之前或之后,某個時間段的日期?,F(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;    
}

相關(guān)文章

  • 修改Laravel5.3中的路由文件與路徑

    修改Laravel5.3中的路由文件與路徑

    本文先是回顧了Laravel5.2中路由的修改,然后給大家用實例代碼介紹了如何修改Laravel5.3中的路由,有需要的小伙伴們可以參考學習。
    2016-08-08
  • php中json_encode中文編碼問題分析

    php中json_encode中文編碼問題分析

    眾所周知使用json_encode可以方便快捷地將對象進行json編碼,但是如果對象的屬性中存在著中文,問題也就隨之而來了。json_encode會將中文轉(zhuǎn)換為unicode編碼
    2011-09-09
  • 解析mysql中UNIX_TIMESTAMP()函數(shù)與php中time()函數(shù)的區(qū)別

    解析mysql中UNIX_TIMESTAMP()函數(shù)與php中time()函數(shù)的區(qū)別

    本篇文章是對mysql中UNIX_TIMESTAMP()函數(shù)與php中time()函數(shù)的區(qū)別進行了詳細的分析介紹,需要的朋友參考下
    2013-06-06
  • php 魔術(shù)方法使用說明

    php 魔術(shù)方法使用說明

    一些在PHP叫魔術(shù)方法的函數(shù),在這里介紹一下:其實在一般的應用中,我們都需要用到他們??!
    2009-10-10
  • PHP使用JpGraph繪制折線圖操作示例【附源碼下載】

    PHP使用JpGraph繪制折線圖操作示例【附源碼下載】

    這篇文章主要介紹了PHP使用JpGraph繪制折線圖操作,結(jié)合實例形式分析了php使用JpGraph的相關(guān)操作技巧與注意事項,并附帶源碼供讀者下載參考,需要的朋友可以參考下
    2019-10-10
  • php-accelerator網(wǎng)站加速PHP緩沖的方法

    php-accelerator網(wǎng)站加速PHP緩沖的方法

    我們知道 Zend 有免費的優(yōu)化引擎針對 PHP 而作,但是 FreeLAMP 這次采用的是一個叫做 PHP Accelerator 的緩沖產(chǎn)品。
    2008-07-07
  • windows下配置apache+php+mysql時出現(xiàn)問題的處理方法

    windows下配置apache+php+mysql時出現(xiàn)問題的處理方法

    windows下配置apache+php+mysql應該是每個phper必須掌握的基礎(chǔ)技能了,這也是熟悉php的一個過程,小編當年自己配環(huán)境的時候也遇到過這樣那樣的問題,現(xiàn)在把當時記錄的幾個問題的處理方法分享給大家
    2014-06-06
  • PHP8新特性之JIT案例講解

    PHP8新特性之JIT案例講解

    這篇文章主要介紹了PHP8新特性之JIT案例講解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下
    2021-09-09
  • PHP+Mysql日期時間如何轉(zhuǎn)換(UNIX時間戳和格式化日期)

    PHP+Mysql日期時間如何轉(zhuǎn)換(UNIX時間戳和格式化日期)

    UNIX時間戳和格式化日期是我們常打交道的兩個時間表示形式,Unix時間戳存儲、處理方便,但是不直觀,格式化日期直觀,但是處理起來不如Unix時間戳那么自如,所以有的時候需要互相轉(zhuǎn)換,下面給出互相轉(zhuǎn)換的幾種轉(zhuǎn)換方式
    2012-07-07
  • PHP常見數(shù)組函數(shù)用法小結(jié)

    PHP常見數(shù)組函數(shù)用法小結(jié)

    這篇文章主要介紹了PHP常見數(shù)組函數(shù)用法,結(jié)合實例形式分析了array_merge、array_slice及array_map函數(shù)的使用技巧,需要的朋友可以參考下
    2016-03-03

最新評論