##language:zh #pragma section-numbers off ##含有章节索引导航的 ZPyUG 文章通用模板 <> ## 默许导航,请保留 <> = 如何将“18/Aug/2008:10:47:23"转换成一个datetime对象? = ##startInc {{{ 风翔万里 reply-to python-cn@googlegroups.com to python-cn`CPyUG`华蟒用户组 date Sat, Aug 23, 2008 at 21:09 subject [CPyUG:63167] 如何将“18/Aug/2008:10:47:23"这样的时间字符串通过datetime.strptime的方式转换成一个datetime对象? }}} == 常解 == {{{ 风翔万里 reply-to python-cn@googlegroups.com to python-cn`CPyUG`华蟒用户组 date Sun, Aug 24, 2008 at 12:24 }}} 感谢以上给与帮助的各位前辈该问题可以结贴了,正确答案是如果希望将单词缩写的月份倒入到datetime类型中可使用%b的方式,例如: {{{#!python #处理日期格式,默认输入格式是18/Aug/2008:10:47:23 def getdateformat(para,pformat='%d/%b/%Y:%H:%M:%S',oformat='%Y/%d/%m%H:%M:%S'): dt=datetime.datetime.strptime(para["localtime"].rstrip(),pformat) return dt.strftime(oformat) }}} ##endInc ---- '''反馈''' 创建 by -- ZoomQuiet [<>]