python - Create list of interval times given start and stop time -


given string start , stop dates/times , number of intervals want count time in between:

import datetime datetime import timedelta     start = '16 sep 2016 00:00:00'  stop= '16 sep 2016 06:00:00.00' scenlength = 21600 # in seconds (21600 6 hours; 18000 5 hours; 14400 4 hours) stepsize = 10 # seconds intervals = scenlength/stepsize 

how create list of dates , times?

i new python , don't have far:

timelist=[]     timespan = [datetime.datetime.strptime(stop,'%d %b %y %h:%m:%s')-datetime.datetime.strptime(start,'%d %b %y %h:%m:%s')]          m in range(0, intervals):         ...         timelist.append(...) 

thanks!

if understood correctly, want find time stamps in regular interval.

that can done python class datetime.timedelta:

import datetime  start = datetime.datetime.strptime('16 sep 2016 00:00:00', '%d %b %y %h:%m:%s') stop = datetime.datetime.strptime('16 sep 2016 06:00:00', '%d %b %y %h:%m:%s')  stepsize = 10 delta = datetime.timedelta(seconds=stepsize)  times = [] while start < stop:     times.append(start)     start += delta  print( times ) 

edit: complete example


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -