>  기사  >  백엔드 개발  >  PHP获取时间段代码

PHP获取时间段代码

WBOY
WBOY원래의
2016-07-25 08:46:171041검색
  1. $start_time = '';
  2. $end_time = '';
  3. switch ($type) {
  4. case 'thisWeek'://本周
  5. $start_time = date("Y-m-d H:i:s",strtotime("-0 week Monday"));
  6. $end_time = date("Y-m-d H:i:s",strtotime("-0 week Sunday"));
  7. break;
  8. case 'lastWeek'://上周
  9. $start_time = date("Y-m-d H:i:s",strtotime("-1 week Monday"));
  10. $end_time = date("Y-m-d H:i:s",strtotime("-1 week Sunday"));
  11. break;
  12. case 'thisMonth'://本月
  13. $start_time = date("Y-m-d H:i:s",strtotime("first day of this month"));
  14. $end_time = date('Y-m-d H:i:s',strtotime("last day of this month"));
  15. break;
  16. case 'lastMonth'://上个月
  17. $start_time = date("Y-m-d H:i:s",strtotime("first day of last month"));
  18. $end_time = date('Y-m-d H:i:s',strtotime("last day of last month"));
  19. break;
  20. case 'lastMonth2'://上上个月
  21. $start_time = date("Y-m-d H:i:s",strtotime("first day of last month -1 month"));
  22. $end_time = date('Y-m-d H:i:s',strtotime("last day of last month -1 month"));
  23. break;
  24. case 'lastMonth3'://上上上个月
  25. $start_time = date("Y-m-d H:i:s",strtotime("first day of last month -2 month"));
  26. $end_time = date('Y-m-d H:i:s',strtotime("last day of last month -2 month"));
  27. break;
  28. default :
  29. $start_time = date("Y-m-d H:i:s");
  30. $end_time = date("Y-m-d H:i:s");
  31. }
复制代码

PHP


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.