我需要能夠將我從sql數據庫接收到的時間對象上的時間轉換爲python。這裏是我正在使用的當前Python代碼,沒有任何轉換。我需要增加2個半小時的時間。在Python中添加2個半小時到時間對象
def getLastReport(self, sql):
self.connectDB()
cursor.execute(sql)
lastReport = cursor.fetchall()
date = lastReport[0][0].strftime('%Y-%m-%d %H:%M UTC')
dataset_id = int(lastReport[0][1])
cursor.close()
DATABASE.close()
return date, dataset_id
我似乎無法讓你的代碼工作。錯誤:回溯(最近一次調用最後一次): 文件「」,第1行,在-toplevel- dt = datetime.strptime(date,'%Y-%m-%d%H:%M') AttributeError :'模塊'對象沒有屬性'strptime' –
Richard
2010-07-21 12:28:56
或者將你的導入改爲'from datetime import datetime'或者將代碼改爲'datetime.datetime.strptime' – AdmiralNemo 2010-07-21 12:44:45