datehelper.php 2.2 KB

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