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');
// 获取当天的时间段内
$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');
相关文章推荐
- hd-1094:A+B for Input-Output Practice (VI)
- hd-1093:A+B for Input-Output Practice (V)
- php学习笔记
- FTPClient上传和下载文件,中文乱码问题解决
- 使用PHP生成二维码的方法汇总
- TP的一些用法
- php翻页
- 理解钩子Hook以及在Thinkphp下利用钩子使用行为扩展
- 如何在win7中提供ftp服务
- Yii框架 多表查询实例
- php 数组排序
- php基础
- Windows 7中无法访问FTP的解决方法
- ThinkPHP验证码类
- PHP运行模式
- ThinkPHP验证码刷新随机数
- ZendFramework2学习笔记 json和ajax
- 项目开发经常使用PHP功能
- php基础
- js验证和PHP验证用户输入的区别