从SQLite数据库表中以可读格式解析日期和时间

时间:2018-02-01 20:43:44

标签: python-3.x sqlite android-sqlite

我正在尝试从一个名为sms的SQLite数据库文件表中解析数据并且它正在工作但是当显示日期和时间时它不可读,它只是一串数字。

如何以可读格式向控制台显示日期和时间?

# import statements
import sqlite3
from sqlite3 import Error
import time
import datetime


# create a database connection to the SQLite database specified by the db_file
def create_connection(db_file):
    try:
        conn = sqlite3.connect(db_file)
        return conn
    except Error as e:
        print(e)

    return None

# Query specific rows in the sms table
def select_data(conn):
    cur = conn.cursor()
    cur.execute("SELECT _id, date, date_sent, read, type, body, seen FROM sms")
    print("Outputting the contents of the sms table within the mmssms.db database file")
    print("\t")
    rows = cur.fetchall()
    for row in rows:

        print(row)

# path to where the db files are stored
def main():
    database = "H:\College Fourth Year\Development Project\Final Year Project 2018\mmssms.db"

     # create a database connection
    conn = create_connection(database)
    with conn:

        # print("Query specific columns")
        select_data(conn)
    # close db connection
    if(conn):
        conn.close()
        print("Database closed")


if __name__ == '__main__':
    main()

0 个答案:

没有答案