I'm writing the time to an XML file and later coming back to compare it against the current time. I've not done this with Python before and the time formatting seems to be pretty strange.
I've managed to put something together if I write the timenow to the XML without milliseconds.
IF the XML has a timestamp like 2016-01-05 00:39:20 then this works:
tree = ET.parse('C:\logs\XMLFILENAME.xml')
for matchlisting in tree.findall('Found'):
age = matchlisting.find('FoundTime').text
dnow=datetime.datetime.now()
print dnow
d2 = datetime.datetime.strptime(age, '%Y-%m-%d %H:%M:%S')
#print d2
print(dnow-d2)
But by default the time.now doesn't give something like 2016-01-05 00:39:20 it adds the milliseconds on the back like 2016-01-05 00:39:20.xxxx.
I don't see an option for the milliseconds in the documentation to handle it with the strptime or a way to write the timenow without the milliseconds which would work as well.
I'm hoping there's some simple syntax to fix one of these. I'd appreciatea pointer here it's been a few hours on what should be fairly straight forward I would of thought.