$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‘)) //获取指定月份的天数
原文地址:https://www.cnblogs.com/beiman/p/11528970.html
时间: 2024-11-10 18:04:41