from datetime import datetime as dt, date, timedelta
import time
startdate= dt.now() - timedelta(days = 7)
enddate= dt.now() - timedelta(days = 1)
HourList=[0,3,6,9,12,15,18,21]
for hour in HourList:
timeFrom = int(time.mktime(dt(startdate.year, startdate.month, startdate.day, hour,0,0,1).timetuple()))
timeTo = int(time.mktime(dt(enddate.year, enddate.month, enddate.day, hour+2,59,59,999).timetuple()))
По приведенному выше коду, я могу l oop через часы. Любые предложения, как l oop через даты. или по общим часам за n дней.
Expected output:
---
first loop
timeFrom --march 01 2020 00:00:00
timeTo --march 01 2020 02:59:59
--second loop
timeFrom --march 01 2020 03:00:00
timeTo --march 01 2020 05:59:59
---third loop
timeFrom --march 01 2020 06:00:00
timeTo --march 01 2020 08:59:59
...
...
..
---lastloop
timeFrom --march 07 2020 21:00:00
timeTo --march 07 2020 23:59:59