您的位置:首页 > 编程语言 > PHP开发

php 时间戳一些示例

2015-07-22 11:40 656 查看
如根据当前时间 确定本天的起止时间

// 获取当天的时间段内
  $nowdate = date("Y-m-d",time());
  $begintime = strtotime($nowdate); //当天的开始 时间戳
  $endtime = $begintime + 60*60*24; //当天的结束 时间戳
  $map['add_time'] = array(array('egt',$begintime),array('lt',$endtime),'AND');

如根据当前时间 确定本月的起止时间

$nowmonth = date("m",time()); //获取当前月
if($nowmonth == '01' || $nowmonth == '03' || $nowmonth == '05' || $nowmonth == '07' || $nowmonth == '08' || $nowmonth == '10' || $nowmonth == '12'){
$nowdate = date("Y-m",time());
$mstarttime = strtotime($nowdate); //本月的开始 时间戳
$mendtime = $mstarttime + 31*60*60*24;

}else if($nowmonth == '02'){
$nowdate = date("Y-m",time());
$mstarttime = strtotime($nowdate); //本月的开始 时间戳
$mendtime = $mstarttime + 28*60*60*24;

}else if($nowmonth == '04' || $nowmonth == '06' || $nowmonth == '09' || $nowmonth == '11'){

$nowdate = date("Y-m",time());
$mstarttime = strtotime($nowdate); //本月的开始 时间戳
$mendtime = $mstarttime + 30*60*60*24; //本月的结束时间
}

$map['add_time'] = array(array('egt',$mstarttime),array('lt',$mendtime),'AND');
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: