是否有一种简单的(内置)方式可以使用日期时间和/或日历将21-Feb-12转换为%d-%m-%Y?或者我需要解析字符串" 21-Feb-12"?任何Pythonic建议都欢迎。感谢。
答案 0 :(得分:2)
使用strptime
并为其指定正确的格式。
from datetime import datetime
print datetime.strptime("21-Feb-12", "%d-%b-%y")
#datetime.datetime(2012, 2, 21, 0, 0)
以下是strptime参考:http://docs.python.org/library/datetime.html#strftime-strptime-behavior