代码如下:
403_5@PHP @H_403_5@date_default_timezone_set('PRC'); //默认时区 @H_403_5@echo "今天:",date("Y-m-d",time()),"
"; @H_403_5@echo "今天:",strtotime("18 june 2008")),"
"; @H_403_5@echo "昨天:",strtotime("-1 day")),"
"; @H_403_5@echo "明天:",strtotime("+1 day")),"
"; @H_403_5@echo "一周后:",strtotime("+1 week")),"
"; @H_403_5@echo "一周零两天四小时两秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")),"
"; @H_403_5@echo "下个星期四:",strtotime("next Thursday")),"
"; @H_403_5@echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."
"; @H_403_5@echo "一个月前:".date("Y-m-d",strtotime("last month"))."
"; @H_403_5@echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."
"; @H_403_5@echo "十年后:".date("Y-m-d",strtotime("+10 year"))."
"; @H_403_5@?> @H_403_5@
@H_403_5@在学习PHP 的时候,经常会用到获取现在之前或之后,某个时间段的日期。现在已经进行收集,大家同时也可以进行扩展丰富@H_403_5@"; @H_403_5@echo "今天:",strtotime("18 june 2008")),"
"; @H_403_5@echo "昨天:",strtotime("-1 day")),"
"; @H_403_5@echo "明天:",strtotime("+1 day")),"
"; @H_403_5@echo "一周后:",strtotime("+1 week")),"
"; @H_403_5@echo "一周零两天四小时两秒后:",date("Y-m-d G:H:s",strtotime("+1 week 2 days 4 hours 2 seconds")),"
"; @H_403_5@echo "下个星期四:",strtotime("next Thursday")),"
"; @H_403_5@echo "上个周一:".date("Y-m-d",strtotime("last Monday"))."
"; @H_403_5@echo "一个月前:".date("Y-m-d",strtotime("last month"))."
"; @H_403_5@echo "一个月后:".date("Y-m-d",strtotime("+1 month"))."
"; @H_403_5@echo "十年后:".date("Y-m-d",strtotime("+10 year"))."
"; @H_403_5@?> @H_403_5@
代码如下:
403_5@//获取当天的星期(1-7)@H_403_5@function GetWeek($times)@H_403_5@{@H_403_5@ $res = date('w',strtotime($times));@H_403_5@ if($res==0)@H_403_5@ $res=7;@H_403_5@ return $res;@H_403_5@}@H_403_5@//获取当天时间@H_403_5@function GetTime($times)@H_403_5@{@H_403_5@ $res = date('H:i',strtotime($times));@H_403_5@ return $res;@H_403_5@}@H_403_5@//获取现在过几月的的时间@H_403_5@function GetMonth($Month,$type='l')@H_403_5@{@H_403_5@ if(!strcmp($type,'b'))@H_403_5@ $res=date("Y-m-d H:i:s",strtotime("-$Month months"));@H_403_5@ if(!strcmp($type,'l'))@H_403_5@ $res=date("Y-m-d H:i:s",strtotime("+$Month months"));@H_403_5@ return $res;@H_403_5@}@H_403_5@//获取当前时间@H_403_5@function GetCurrentDateTime()@H_403_5@{@H_403_5@ $res=date("Y-m-d H:i:s",time());@H_403_5@ return $res;@H_403_5@}@H_403_5@//获取当前时间隔几小时之前或之后的时间@H_403_5@function GetDiffHours($hours,strtotime("-$hours hour"));@H_403_5@ if(!strcmp($type,strtotime("+$hours hour"));@H_403_5@ return $res; @H_403_5@}@H_403_5@//间隔几分钟之前或之后的时间@H_403_5@function GetDiffMinute($Minute,strtotime("-$Minute minute"));@H_403_5@ if(!strcmp($type,strtotime("+$Minute minute"));@H_403_5@ return $res; @H_403_5@}@H_403_5@//间隔几秒之前或之后的时间@H_403_5@function GetDiffSec($sec,strtotime("-$sec second"));@H_403_5@ if(!strcmp($type,strtotime("+$sec second"));@H_403_5@ return $res; @H_403_5@}
原文链接:https://www.f2er.com/php/26800.html//间隔几个星期之前或之后的时间@H_403_5@function GetDiffWeek($Week,strtotime("-$Week week"));@H_403_5@ if(!strcmp($type,strtotime("+$Week week"));@H_403_5@ return $res; @H_403_5@}@H_403_5@// 间隔几天之间的时间@H_403_5@function GetDiffDays($days,strtotime("-$days day"));@H_403_5@ if(!strcmp($type,strtotime("+$days day"));@H_403_5@ return $res; @H_403_5@}@H_403_5@//间隔几年之前或之后的时间@H_403_5@function GetDiffYears($year,strtotime("-$year year"));@H_403_5@ if(!strcmp($type,strtotime("+$year year"));@H_403_5@ return $res; @H_403_5@}@H_403_5@