我需要Excel中的数据-这样的int类型的date(20180301)和time(121220)。我想将excel导入mysql,使用python将datetamp(%t-%m-%d%H:%M:%S)转换为一个库仑。import xlrdimport pymysqlimport timeimport datetime#open the workbook and define rhe worksheetbook = xlrd.open_workbook("d:/waiting2.xlsx")sheet = book.sheet_by_index(0)ts = time.time()timestamp = datetime.datetime.formtimestamp(ts).strftime('%t-%m-%d %H:%M:%S')#sheet = book.sheet_by_index(0)#establish a mysql connectiondatabase = pymysql.connect(host="localhost", user='root', password='1234',db='test')#get the cursor, which is used to traverse the database, line by linecursor = database.cursor()try: cursor.execute("""INSERT into test(date+time) values($s)""", (timestamp)) database.commit()except: database.rollback()database.close()AttributeError:类型对象“ datetime.datetime”没有属性“ formtimestamp”
添加回答
举报
0/150
提交
取消