//获取当天的星期(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;
}
网友评论