PHP 获取今天,昨天,前天,过去7天,过去30天,本周,上周的开始和结束时间

Php  
  1. protected function selectTime($key)
  2. {
  3. switch ($key) {
  4. //今天
  5. case 1:
  6. $time[0] = mktime(0,0,0,date('m'),date('d'),date('Y'));
  7. $time[1] = mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
  8. break;
  9. //昨天
  10. case 2:
  11. $time[0] = mktime(0,0,0,date('m'),date('d')-1,date('Y'));
  12. $time[1] = mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
  13. break;
  14. //前天
  15. case 3:
  16. $time[0] = mktime(0,0,0,date('m'),date('d')-2,date('Y'));
  17. $time[1] = mktime(0,0,0,date('m'),date('d')-1,date('Y'))-1;
  18. break;
  19. //过去7天
  20. case 4:
  21. $time[0] = mktime(0,0,0,date('m'),date('d')-7,date('Y'));
  22. $time[1] = mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
  23. break;
  24. //过去30天
  25. case 5:
  26. $time[0] = mktime(0,0,0,date('m'),date('d')-30,date('Y'));
  27. $time[1] = mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
  28. break;
  29. //本周
  30. case 6:
  31. $time[0] = mktime(0, 0, 0, date('m'), (date('d') - (date('w')>0 ? date('w') : 7) + 1), date('Y'));
  32. $time[1] = mktime(0, 0, 0, date('m'), (date('d') - (date('w')>0 ? date('w') : 7) + 7), date('Y'));
  33. break;
  34. //上周
  35. case 7:
  36. $time[0] = mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'));
  37. $time[1] = mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'));
  38. break;
  39. //本月
  40. case 8:
  41. $time[0] = mktime(0,0,0,date('m'),1,date('Y'));
  42. $time[1] = mktime(23,59,59,date('m'),date('t'),date('Y'));
  43. break;
  44. //上月
  45. case 9:
  46. $time[0] = mktime(0, 0 , 0,date("m")-1,1,date("Y"));
  47. $time[1] = mktime(23,59,59,date("m") ,0,date("Y"));
  48. break;
  49. }
  50. return $time;
  51. }


评论 0

发表评论

Top