|
@@ -0,0 +1,43 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+class DateUtil {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取某个时间段内所有月份 (包含开头结尾月份)
|
|
|
+ * @param minDate
|
|
|
+ * @param maxDate
|
|
|
+ * @return
|
|
|
+ * @throws ParseException
|
|
|
+ */
|
|
|
+ public static function getMonthBetweenDates($minDate, $maxDate) {
|
|
|
+ $result = [];
|
|
|
+ $sTime = strtotime(date('Y-m-01', strtotime($minDate)));
|
|
|
+ $eTime = strtotime(date('Y-m-01', strtotime($maxDate)));
|
|
|
+ $months = [];
|
|
|
+ while ($sTime <= $eTime) {
|
|
|
+ $months[] = date('Y-m', $sTime);
|
|
|
+ $sTime = strtotime('next month', $sTime);
|
|
|
+ }
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取某个时间段内所有月份 (包含开头不包含结尾月份)
|
|
|
+ * @param minDate
|
|
|
+ * @param maxDate
|
|
|
+ * @return
|
|
|
+ * @throws ParseException
|
|
|
+ */
|
|
|
+ public static function getMonthBetweenDatesNotEnd($minDate, $maxDate) {
|
|
|
+ $result = [];
|
|
|
+ $sTime = strtotime(date('Y-m-01', strtotime($minDate)));
|
|
|
+ $eTime = strtotime(date('Y-m-01', strtotime($maxDate)));
|
|
|
+ $months = [];
|
|
|
+ while ($sTime < $eTime) {
|
|
|
+ $months[] = date('Y-m', $sTime);
|
|
|
+ $sTime = strtotime('next month', $sTime);
|
|
|
+ }
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|