I have the following code in which am trying to read the time string and reduce the time by 8 hours and print in a human readable format but am running into below error. Can anyone provide guidance on how to fix this?
import time
from datetime import datetime
time_string = '2018-07-16T23:50:55+0000'
#Reduct 8 hours and print in human readable format
struct_time = time.strptime(time_string, "%Y-%m-%dT%H:%M:%S+0000")
t = datetime.datetime(*struct_time[:6])
delta = datetime.timedelta(hours=8)
print(t+delta)
Error:
t = datetime.datetime(*struct_time[:6])
AttributeError: type object 'datetime.datetime' has no attribute 'datetime'
from datetime import datetimethen usedatetime(*...); orimport datetimethen usedatetime.datetime(*...). The module nameddatetimecontains (amongst other things) a class nameddatetime, so you have to be aware of which of those names is currently in scope. You're currently trying to accessdatetime.datetime.datetimewhich doesn't exist, hence the error.from datetime import datetimein my code,why is it still complaining?datetime, you're trying to instantiate it as if you'd imported the whole module asdatetime.