博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php 获取时间段 今天昨天本周上周本月上月本季度本年去年
阅读量:4147 次
发布时间:2019-05-25

本文共 2802 字,大约阅读时间需要 9 分钟。

/**获取时间段 * @param $name * @param $param */function gettimestamp($name = 'today',$param = ''){    switch ($name){        case 'today'://今天            $timeamp['start'] = strtotime(date('Y-m-d'));            $timeamp['end'] = strtotime(date('Y-m-d',strtotime('+1 day')));            break;        case 'yesterday'://昨天            $timeamp['start'] = strtotime(date('Y-m-d',strtotime('-1 day')));            $timeamp['end'] = strtotime(date('Y-m-d'));            break;        case 'beforyesterday'://前天            $timeamp['start'] = strtotime(date('Y-m-d',strtotime('-2 day')));            $timeamp['end'] = strtotime(date('Y-m-d',strtotime('-1 day')));            break;        case 'nowmonth'://本月            $timeamp['start'] = strtotime(date('Y-m-01'));            $timeamp['end'] = strtotime(date('Y-m-d',strtotime('+1 day')));            break;        case 'permonth'://上月            $timeamp['start'] = strtotime(date('Y-m-01',strtotime('-1 month')));            $timeamp['end'] = strtotime(date('Y-m-01'));            break;        case 'preweek'://上周 注意我们是从周一开始算            $timeamp['start'] = strtotime(date('Y-m-d',strtotime('-2 week Monday')));            $timeamp['end'] = strtotime(date('Y-m-d',strtotime('-1 week Monday +1 day')));            break;        case 'nowweek'://本周            $timeamp['start'] = strtotime(date('Y-m-d',strtotime('-1 week Monday')));            $timeamp['end'] = strtotime(date('Y-m-d',strtotime('+1 day')));            break;        case 'preday'://30            $timeamp['start'] = strtotime(date('Y-m-d'),strtotime($param.' day'));            $timeamp['end'] = strtotime(date('Y-m-d'));            break;        case 'nextday'://30            $timeamp['start'] = strtotime(date('Y-m-d'));            $timeamp['end'] = strtotime(date('Y-m-d'),strtotime($param.' day'));            break;        case 'preyear'://去年            $timeamp['start'] = strtotime(date('Y-01-01',strtotime('-1 year')));            $timeamp['end'] = strtotime(date('Y-12-31',strtotime('-1 year')));            break;        case 'nowyear'://今年            $timeamp['start'] = strtotime(date('Y-01-01'));            $timeamp['end'] = strtotime(date('Y-m-d',strtotime('+1 day')));            break;        case 'quarter'://季度            $quarter = empty($param) ? ceil((date('n'))/3) : $param;//获取当前季度            $timeamp['start'] = mktime(0, 0, 0,$quarter*3-2,1,date('Y'));            $timeamp['end'] = mktime(0, 0, 0,$quarter*3+1,1,date('Y'));//            $timeamp['end'] = mktime(23,59,59,$quarter*3,date('t',mktime(0, 0 , 0,$quarter*3,1,date("Y"))),date('Y'));            break;        default:            $timeamp['start'] = strtotime(date('Y-m-d'));            $timeamp['end'] = strtotime(date('Y-m-d',strtotime('+1 day')));            break;    }    return $timeamp;}

php 获取某个时间段

转载地址:http://msiti.baihongyu.com/

你可能感兴趣的文章
深入入门正则表达式(java) - 命名捕获
查看>>
使用bash解析xml
查看>>
android系统提供的常用命令行工具
查看>>
【Python基础1】变量和字符串定义
查看>>
【Python基础2】python字符串方法及格式设置
查看>>
【Python】random生成随机数
查看>>
【Python基础3】数字类型与常用运算
查看>>
Jenkins迁移jobs
查看>>
【Python基础4】for循环、while循环与if分支
查看>>
【Python基础5】列表和元组
查看>>
【Python基础6】格式化字符串
查看>>
【Python基础7】字典
查看>>
【Python基础8】函数参数
查看>>
【Python基础9】浅谈深浅拷贝及变量赋值
查看>>
Jenkins定制一个具有筛选功能的列表视图
查看>>
【Python基础10】探索模块
查看>>
【Python】将txt文件转换为html
查看>>
[Linux]Shell脚本实现按照模块信息拆分文件内容
查看>>
idea添加gradle模块报错The project is already registered
查看>>
在C++中如何实现模板函数的外部调用
查看>>