php 获取不同时段时间戳
Posted beiman
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 获取不同时段时间戳相关的知识,希望对你有一定的参考价值。
$week=date(‘w‘); $week==0?$week=7 //如果是周日回返回零,若一周从周日开始则不需要该语句 switch ($this->Arg[‘time_range‘]) case ‘0‘://今天时间戳 $Group = ‘`Y`,`M`,`D`‘; $start_time = mktime(0, 0, 0, date(‘m‘), date(‘d‘), date(‘Y‘)); $end_time = mktime(0, 0, 0, date(‘m‘), date(‘d‘) + 1, date(‘Y‘)) - 1; break; case ‘1‘://昨天时间戳 $Group = ‘`Y`,`M`,`D`‘; $start_time = mktime(0, 0, 0, date(‘m‘), date(‘d‘) - 1, date(‘Y‘)); $end_time = mktime(0, 0, 0, date(‘m‘), date(‘d‘), date(‘Y‘)) - 1; break; case ‘2‘://本周时间戳 $start_time = mktime(0, 0, 0, date(‘m‘), date(‘d‘) - $week + 1 - 0, date(‘Y‘)); $end_time = mktime(23, 59, 59, date(‘m‘), date(‘d‘) - $week + 7 - 0, date(‘Y‘)); $Group = ‘`Y`,`M`,`D`‘; break; case ‘3‘://上周时间戳 $start_time = mktime(0, 0, 0, date(‘m‘), date(‘d‘) - $week + 1 - 7, date(‘Y‘)); $end_time = mktime(23, 59, 59, date(‘m‘), date(‘d‘) - $week + 7 - 7, date(‘Y‘)); $Group = ‘`Y`,`M`,`D`‘; break; case ‘4‘://本月时间戳 $start_time = mktime(0, 0, 0, date(‘m‘), 1, date(‘Y‘)); $end_time = mktime(23, 59, 59, date(‘m‘), date(‘t‘), date(‘Y‘)); $Group = ‘`Y`,`M`,`D`‘; break; case ‘5‘://上月时间戳 $start_time = mktime(0, 0, 0, date(‘m‘) - 1, 1, date(‘Y‘)); $end_time = mktime(23, 59, 59, date(‘m‘) - 1, cal_days_in_month(CAL_GREGORIAN, date(‘m‘) - 1, date(‘Y‘)), date(‘Y‘)); $Group = ‘`Y`,`M`,`D`‘; break; case ‘6‘://今年 $start_time = mktime(0, 0, 0, 1, 1, date(‘Y‘)); $end_time = mktime(23, 59, 59, 12, 31, date(‘Y‘)); $Group = ‘`Y`,`M`‘; break; ;
注:
cal_days_in_month(CAL_GREGORIAN, date(‘m‘) - 1, date(‘Y‘)) //获取指定月份的天数
以上是关于php 获取不同时段时间戳的主要内容,如果未能解决你的问题,请参考以下文章