我知道有各种类似的帖子。 并且充分意识到strptime
和strftime
函数。
我的问题有点不同。
python中最简单的方法是将字符串隐式地转换为日期/日期对象。
或者显式地,是一个接受表示日期或日期对象的字符串的函数。
与SQL date_object = 'string_of_date'
类似
我猜是
cast_date=lambda x:x if type(x)=='datetime' else strptime(x,'%%%')#dosen't really work
cast_date=lambda x:strptime(str(x),'%%%') #edit
或类似的将工作,但我宁愿使用原生的东西,如果存在。
谢谢