2016-11-17 4 views
1

与えられた文字列指定した間隔時間のリストを作成します。私はその間の時間をカウントしたいことで開始と停止の日付/時刻をし、間隔の数開始時間と終了時間

import datetime 
from datetime import timedelta  
Start = '16 Sep 2016 00:00:00' 
Stop= '16 Sep 2016 06:00:00.00' 
ScenLength = 21600 # in seconds (21600 for 6 hours; 18000 for 5 hours; 14400 for 4 hours) 
stepsize = 10 # seconds 
Intervals = ScenLength/stepsize 

どのように私はのリストを作成しますその日時?

私は、Pythonに新しいですし、ずっと今のところありません。

TimeList=[]  
TimeSpan = [datetime.datetime.strptime(Stop,'%d %b %Y %H:%M:%S')-datetime.datetime.strptime(Start,'%d %b %Y %H:%M:%S')]  
    for m in range(0, Intervals): 
     ... 
     TimeList.append(...) 

ありがとう!

答えて

0

私が正しく理解していれば、定期的にタイムスタンプを見つけたいと思っています。 Pythonクラス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) 

編集:完全な例

+0

ありがとうございました!これは完全に機能しました。 – LHB

関連する問題