python 读取 mysql 日期型字段

course["time"] = record[7].strftime('%Y-%m-%d %H:%M:%S')

 

import time, datetime

import pymysql
import json

conn = pymysql.connect("localhost", "username", "password", "db")

cursor = conn.cursor()

cursor.execute("select * from table")

print(cursor.rowcount)
courses = []
for i in range(cursor.rowcount):
    record = cursor.fetchone()
    course = {}

    course["col1"] = record[1]
    course["col12"] = record[2].strftime('%Y-%m-%d %H:%M:%S')

    courses.append(course)
print("mysql=", courses)

conn.close()

 

你可能感兴趣的:(flask,python)