简体   繁体   中英

QDate is not convertible to datetime

I have a geodataframe which I'm adding some column data to, all the same length, to get this in the correct format for another application I do the following:

revdate = datetime.date(1999, 12, 20).strftime("%Y-%m-%d")

gdf = gpd.GeoDataFrame()
gdf['revdate'] = revdate
gdf['revdate'] = pd.to_datetime(gdf['revdate']).dt.strftime("%m/%d/%Y")

Incorporating PyQt5 I use a DateEdit field, I need to go through the same procedure as above:

revdate = self.dateEditRevDate.date()

gdf = gpd.GeoDataFrame()
gdf['revdate'] = revdate
gdf['revdate'] = pd.to_datetime(gdf['revdate']).dt.strftime("%m/%d/%Y")

The date is received This date is in format PyQt5.QtCore.QDate(2000, 1, 1)

It trips up on this line:

gdf['hs2_revdate'] = pd.to_datetime(gdf['hs2_revdate']).dt.strftime("%m/%d/%Y")

With a type error TypeError: <class 'PyQt5.QtCore.QDate'> is not convertible to datetime

Any pointers appreciated.

尝试使用 QDate 时不要太复杂,因为您可以使用toPyDate()方法将其转换为datetime.date()

revdate = self.dateEditRevDate.date().toPyDate().strftime("%Y-%m-%d")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM