我想减去我从tt.txt
文件导入的两个时间实例。但是strptime
的参数必须为string
(格式为'%H.%M')。我该如何解决这个问题?
我的代码:
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
data = np.genfromtext('tt.txt', delimiter= ' ')
sn = data[ :, ][ :,0]
dt = data[ :, ][ :,1] # dt = depature time, 2nd column of table
at = data[ :, ][ :,2] # at = arrival time, 3rd column of table
str1 = dt[3]
str2 = at[3]
start = datetime.strptime(str1, '%H.%M')
end = datetime.strptime(str2, '%H.%M')
c = end - start
print(c)