When learning PHP, it is often used to get A date in a certain period of time before or after now. Now that it has been collected, you can also expand and enrich
//Get the day of the week (1-7)
function GetWeek($times)
{
$res = date('w', strtotime($times));
if($res==0)
$res=7;
return $res;
}
//Get the time of the day
function GetTime($times)
{
$res = date('H:i ', strtotime($times));
return $res;
}
//Get the time in several months now
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;
}
//Get the current time
function GetCurrentDateTime()
{
$res=date("Y-m-d H:i:s",time());
return $res;
}
//Get the time before or after the current time interval in hours
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;
}
//A few minutes before or after time
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;
}
//The time before or after the interval in seconds
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;
}
//Time before or after a few weeks
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; ($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" ); 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;
}
http://www.bkjia.com/PHPjc/326523.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326523.htmlTechArticlePHP output time difference function copy code code is as follows: ?php date_default_timezone_set('PRC'); //Default time zone echo " Today:",date("Y-m-d",time()),"br"; echo "Today:",date("Y-m-d",strt...