国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > PHP > 正文

PHP輸出時間差函數代碼

2024-05-04 23:08:41
字體:
來源:轉載
供稿:網友

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 的時候,經常會用到獲取現在之前或之后,某個時間段的日期?,F在已經進行收集,大家同時也可以進行擴展豐富

復制代碼 代碼如下:


//獲取當天的星期(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;
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 铅山县| 平安县| 永新县| 江阴市| 沁源县| 石景山区| 静宁县| 康定县| 射洪县| 沭阳县| 博白县| 靖州| 漠河县| 武川县| 徐汇区| 江都市| 灌云县| 库伦旗| 且末县| 海晏县| 晋江市| 阜阳市| 巴东县| 江阴市| 舟山市| 来安县| 花垣县| 松潘县| 论坛| 怀仁县| 漳平市| 原平市| 和龙市| 德兴市| 宝坻区| 梁平县| 额尔古纳市| 永顺县| 永顺县| 汉寿县| 泰州市|