Python MySQLdb - 如何转换datetime.datetime?

时间:2015-08-19 02:07:31

标签: python mysql datetime

我从MySQLdb - datetime.datetime(2015, 8, 13, 16, 52, 53)

获得此类结果

如何将其转换为可读的内容,例如' 2011-11-03 18:21:26'?

   # Open database connection
   db = MySQLdb.connect(user = "root", passwd = "xxx", db = "python", host = "127.0.0.1", cursorclass = MySQLdb.cursors.DictCursor)

   # prepare a cursor object using cursor() method
   cursor = db.cursor()

   # execute SQL query using execute() method.
   cursor.execute("SELECT * FROM users")

   # Fetch a single row using fetchone() method.
   data = cursor.fetchall()

   print data

结果,

  

({' first_name':' John',' last_name':' Smith',' user_id': 4L,   ' created_on':无,'地址':无,' updated_on':   datetime.datetime(2015,8,13,16,52,53)},{' first_name':' Jane',   ' last_name':' Heart',' user_id':5L,' created_on':无,'地址':   无,' updated_on':datetime.datetime(2015,8,13,16,52,53)},   {' first_name':' Dom',' last_name':' Robinsons',' user_id':6L,   ' created_on':无,'地址':无,' updated_on':   datetime.datetime(2015,8,13,16,53,33)},{' first_name':' Pete',   ' last_name':' Hand',' user_id':7L,' created_on':无,'地址':   没有,' updated_on':datetime.datetime(2015,8,13,16,53,33)})

0 个答案:

没有答案