使用python从mysql获取时间

使用python从mysql获取时间,python,mysql,time,Python,Mysql,Time,我正在使用下面的代码从mysql获取名为fajr\u start的时间实体。我可以打印格式为:5:27:00的fajr_begins,如何将其转换为python中的时间格式,以便我可以操纵时间并添加15分钟 cnx = mysql.connector.connect(host=mysql_remote_host, user=mysql_remote_host_user, password=mysql_remote_host_password, database=mysql_remote_host

我正在使用下面的代码从
mysql
获取名为
fajr\u start
的时间实体。我可以打印格式为:5:27:00的
fajr_begins
,如何将其转换为python中的时间格式,以便我可以操纵时间并添加15分钟

cnx = mysql.connector.connect(host=mysql_remote_host, user=mysql_remote_host_user, password=mysql_remote_host_password, database=mysql_remote_host_database)
cursor = cnx.cursor()
cursor.execute("select * from prayertimes where DATE(date) = DATE(NOW())" )
results = cursor.fetchall()
id, date, fajr_begins, fajr_jamaat, sunrise, zuhr_begins, zuhr_jamaat, asr_begins, asr_jamaat, maghrib_jamaat, isha_begins, isha_jamaat = results[0]
cursor.close()
print fajr_begins

您必须使用转换来转换它<代码>时间增量将用于添加分钟数

>>> from datetime import datetime, timedelta
>>> a = "05:27:00"
>>> b = datetime.strptime(a, "%H:%M:%S")
>>> print b
1900-01-01 05:27:00
>>> c = timedelta(minutes=15)
>>> print c
0:15:00
>>> print b+c
1900-01-01 05:42:00

python中是否有不带日期的时间实例?是的,python有
time
模块,但您无法执行
add
minutes、hours、days等直接操作。。。。timedelta无法添加timetuple。谢谢,所以我想我需要在添加15minsf=c.strftime(“%H:%M:%S”)后转换回时间