我希望将作业的持续时间保存在python3.x中,并将其保存到MySQL 5.7时间字段。
datetime.datetime.now() - datetime.datetime(2020, 5, 16, 15, 36, 52, 132454)返回:
datetime.timedelta(seconds=7635, microseconds=282960)如何从这个输出中检索秒,以便将它们放入我的MySQL语句中?
发布于 2020-05-16 16:10:28
为了避免您看到的时区问题,我会尝试这样的方法:
import datetime as dt
import mysql.connector
total_seconds = dt.timedelta(seconds=7635, microseconds=282960).total_seconds()
conn = mysql.connector.connect(user='username', database='your_database')
cursor = conn.cursor()
cursor.execute("""INSERT INTO your_table
(your_time_field)
VALUES (SEC_TO_TIME(%s));""",(total_seconds,))https://stackoverflow.com/questions/61839456
复制相似问题