我有我使用轉換成ISO格式的日期:轉換日期爲datetime對象蟒蛇
#createDate is fetched from a json output of an API
createDate = device['createDate']
# Convert into iso format
# Sample output value : 2014-11-13T16:23:19+00:00
create_date_utcFormat = dateparser.parse(createDate).astimezone(tz.tzutc()).isoformat()
當我嘗試添加該對象到DB我得到SQLite DateTime type only accepts Python datetime and date objects as input.
我怎麼能轉換成create_date_utcFormat
DateTime對象?
好眼睛(因爲我已經與python日期對象摔跤了一分鐘),修好了! – Anna
感謝您指出這一點,這確實非常有用。但我得到了'TypeError:datetime.datetime(2014,11,13,16,23,19,tzinfo = tzutc())不是JSON序列化'當我試圖存儲在json對象中。 – aaj