python摆脱默认日期1900-01-01

时间:2015-06-04 17:13:49

标签: python datetime

我想知道我是否可以在不改变太多代码的情况下摆脱输出中的1900-01-01。我知道有一个解决这个问题,但我不明白如何在不改变所有内容的情况下将这些行应用于我的代码。如果我能得到一些giudance,我会非常感激!

import csv
from datetime import datetime
time_difference= open('Book1.csv')#it is important that within the csv file that the times do not have extra spaces before, that they are foramtted to military time and that these settings are saved before code is ran
time_difference_csv=csv.reader(time_difference)

for row in time_difference_csv:
    w = [[datetime.strptime(i[0],'%H:%M:%S')]+ [datetime.strptime(i[1],'%H:%M:%S')] for i in time_difference_csv]
for row in w:
   p= (row[1]-row[0])
for row in w:
    l= (row[1]-row[0]) + row[0]

td= open('121Times3.csv')#imports csv with the list of times from one time source; e.g. just the scanner times
td_csv=csv.reader(td)
firstline = True

for row in td_csv:
    if firstline:    #skip first line
        firstline = False
        continue
# parse the line
for row in td_csv:
    k = [[datetime.time.strptime(i[0],'%H:%M:%S')] for i in td_csv]

for row in k:#adds the difference found earlier to all the times on the  csv. Converts all the scanner times to the wall times.
    print row[0] + p

0 个答案:

没有答案