datehelper.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * 获得系统年份数组
  4. */
  5. function getSystemYearArr(){
  6. $year_arr = array('2017'=>'2017','2018'=>'2018','2019'=>'2019','2020'=>'2020','2021'=>'2021','2022'=>'2022','2023'=>'2023','2024'=>'2024','2025'=>'2025','2026'=>'2026','2027'=>'2027');
  7. return $year_arr;
  8. }
  9. /**
  10. * 获得系统月份数组
  11. */
  12. function getSystemMonthArr(){
  13. $month_arr = array('1'=>'01','2'=>'02','3'=>'03','4'=>'04','5'=>'05','6'=>'06','7'=>'07','8'=>'08','9'=>'09','10'=>'10','11'=>'11','12'=>'12');
  14. return $month_arr;
  15. }
  16. /**
  17. * 获得系统周数组
  18. */
  19. function getSystemWeekArr(){
  20. $week_arr = array('1'=>'周一','2'=>'周二','3'=>'周三','4'=>'周四','5'=>'周五','6'=>'周六','7'=>'周日');
  21. return $week_arr;
  22. }
  23. /**
  24. * 获取某月的最后一天
  25. */
  26. function getMonthLastDay($year, $month){
  27. $t = mktime(0, 0, 0, $month + 1, 1, $year);
  28. $t = $t - 60 * 60 * 24;
  29. return $t;
  30. }
  31. /**
  32. * 获得系统某月的周数组,第一周不足的需要补足
  33. */
  34. function getMonthWeekArr($current_year, $current_month){
  35. //该月第一天
  36. $firstday = strtotime($current_year.'-'.$current_month.'-01');
  37. //该月的第一周有几天
  38. $firstweekday = (7 - date('N',$firstday) +1);
  39. //计算该月第一个周一的时间
  40. $starttime = $firstday-3600*24*(7-$firstweekday);
  41. //该月的最后一天
  42. $lastday = strtotime($current_year.'-'.$current_month.'-01'." +1 month -1 day");
  43. //该月的最后一周有几天
  44. $lastweekday = date('N',$lastday);
  45. //该月的最后一个周末的时间
  46. $endtime = $lastday-3600*24*($lastweekday%7);
  47. $step = 3600*24*7;//步长值
  48. $week_arr = array();
  49. for ($i=$starttime; $i<$endtime; $i= $i+3600*24*7){
  50. $week_arr[] = array('key'=>date('Y-m-d',$i).'|'.date('Y-m-d',$i+3600*24*6), 'val'=>date('Y-m-d',$i).'~'.date('Y-m-d',$i+3600*24*6));
  51. }
  52. return $week_arr;
  53. }
  54. /**
  55. * 获取本周的开始时间和结束时间
  56. */
  57. function getWeek_SdateAndEdate($current_time){
  58. $current_time = strtotime(date('Y-m-d',$current_time));
  59. $return_arr['sdate'] = date('Y-m-d', $current_time-86400*(date('N',$current_time) - 1));
  60. $return_arr['edate'] = date('Y-m-d', $current_time+86400*(7- date('N',$current_time)));
  61. return $return_arr;
  62. }