如何将 PyQt5 中的 QDate 转换为 datetime.date? [英] How can you convert QDate in PyQt5 to a datetime.date?

查看:86
本文介绍了如何将 PyQt5 中的 QDate 转换为 datetime.date?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将从 QDateEdit 收集的日期转换为 datetime.date 以在 sqlite3 数据库中使用.我已经看到在 PyQt4 中你可以使用 toPyDateTime 但它似乎不在 PyQt5 中.如果这个函数完全没有了,有没有办法把QDate转成字符串?

解决方案

您使用的是哪个版本的 PyQt5?

<预><代码>>>>从 PyQt5.QtCore 导入 QDate, QDateTime>>>QDate.currentDate().toPyDate()datetime.date(2014, 3, 17)>>>QDateTime.currentDateTime().toPyDateTime()datetime.datetime(2014, 3, 17, 19, 9, 45, 974000)

这是将 Qt-5.2.1 与 PyQt-5.2 或 PyQt-5.1.1 一起使用.

I am trying to convert a date gathered from a QDateEdit into datetime.date for use in a sqlite3 database. I have seen that in PyQt4 you could use toPyDateTime however it doesnt seem to be in PyQt5. If this function is completely gone is there a way to convert QDate into a string?

解决方案

What version of PyQt5 are you using?

>>> from PyQt5.QtCore import QDate, QDateTime
>>> QDate.currentDate().toPyDate()
datetime.date(2014, 3, 17)
>>> QDateTime.currentDateTime().toPyDateTime()
datetime.datetime(2014, 3, 17, 19, 9, 45, 974000)

This is using Qt-5.2.1 with PyQt-5.2 or PyQt-5.1.1.

这篇关于如何将 PyQt5 中的 QDate 转换为 datetime.date?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆