from datetime import date
from PyQt5.QtCore import QDate
# 用datetime.date 实现
# 获得今天的日期
today_date = date.today() # 2024-12-13 <class 'datetime.date'>
# 明天的日期
tomorrow_date = today_date + timedelta(1) # 2024-12-14 <class 'datetime.date'>
# datetime.date --> str
# 将今天的日期转换为str类型
today_date_str = today_date.isoformat() # 2024-12-13 <class 'str'>
# str --> datetime.date
# 将str类型的日期转换成datetime.date类型
today_date_date = date(*map(int,today_date_str.split('-')) # 2024-12-13 <class 'datetime.date'>
# 'PyQt5.QtCore.QDate' -->'datetime.date'
now_qdate = QDate.currentDate() # <class 'PyQt5.QtCore.QDate'>
now_date = now_qdate .toPyDate() # 转换类型 <class 'datetime.date'>
标签:QDate,PyQt5,datetime,str,date,QtCore,today
From: https://www.cnblogs.com/hjl20200115/p/18605352