如何将下面的字符串日期转换成python中的日期格式。
input:
date='15-MARCH-2015'
expected output:
2015-03-15
我尝试使用 datetime.strftime
和 datetime.strptime
。它不接受这种格式。
最佳答案
您可以使用具有适当格式的datetime.strptime
:
>>> datetime.strptime('15-MARCH-2015','%d-%B-%Y')
datetime.datetime(2015, 3, 15, 0, 0)
阅读有关 datetime.strptime
和日期格式的更多信息:https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior
关于python - 在python中将字符串日期转换为日期格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30819423/