亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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í)間段的日期。現(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)在過(guò)幾月的的時(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;    
}

相關(guān)文章

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

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

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

    php中json_encode中文編碼問(wèn)題分析

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

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

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

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

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

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

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

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

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

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

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

    PHP8新特性之JIT案例講解

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

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

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

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

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

最新評(píng)論