|
@@ -14,6 +14,29 @@ class DateUtils:
|
|
|
self.daydelta = timedelta(days=1)
|
|
|
self.now = datetime.now()
|
|
|
|
|
|
+
|
|
|
+ def add_days(self,str, interval):
|
|
|
+ return (datetime.strptime(str,'%Y-%m-%d')+timedelta(days=interval)).strftime('%Y-%m-%d')
|
|
|
+
|
|
|
+
|
|
|
+ def split_date(self,start, end, interval, func):
|
|
|
+ """把时间拆分多次运行"""
|
|
|
+ st = start
|
|
|
+ et = self.add_days(st, interval - 1)
|
|
|
+
|
|
|
+ while True:
|
|
|
+ if et >= end:
|
|
|
+ et = end
|
|
|
+ print(f"{st}~{et}")
|
|
|
+ func(st, et)
|
|
|
+ break
|
|
|
+ else:
|
|
|
+ print(f"{st}~{et}")
|
|
|
+ func(st,et)
|
|
|
+ st=self.add_days(et, 1)
|
|
|
+ et=self.add_days(st, interval - 1)
|
|
|
+
|
|
|
+
|
|
|
def getDateLists(self, begin, end):
|
|
|
"""
|
|
|
返回一个时间列表
|
|
@@ -283,12 +306,5 @@ class DateUtils:
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
ut = DateUtils()
|
|
|
- end = ut.now.strftime('%Y-%m') + '-01 00:00:00'
|
|
|
- # begin = ut.get_n_month_ago_begin(ut.now.strftime('%Y-%m'), 1) + '-01 00:00:00'
|
|
|
- # print(ut.get_n_pre_month_first_day(0))
|
|
|
- # ut.today = date(2018, 1, 1)
|
|
|
- # print(ut.month_first_day())
|
|
|
- # a='2021-01-01 00:01:01'
|
|
|
- # b=datetime.strptime(a,'%Y-%m-%d %H:%M:%S')
|
|
|
- # print(b.hour)
|
|
|
- # print(ut.now.hour)
|
|
|
+ # end = ut.now.strftime('%Y-%m') + '-01 00:00:00'
|
|
|
+
|