如何将“18/Aug/2008:10:47:23"转换成一个datetime对象?

风翔万里 <[email protected]>
reply-to        [email protected]
to      python-cn`CPyUG`华蟒用户组 <[email protected]>
date    Sat, Aug 23, 2008 at 21:09
subject [CPyUG:63167] 如何将“18/Aug/2008:10:47:23"这样的时间字符串通过datetime.strptime的方式转换成一个datetime对象?

常解

风翔万里 <[email protected]>
reply-to        [email protected]
to      python-cn`CPyUG`华蟒用户组 <[email protected]>
date    Sun, Aug 24, 2008 at 12:24

感谢以上给与帮助的各位前辈该问题可以结贴了,正确答案是如果希望将单词缩写的月份倒入到datetime类型中可使用%b的方式,例如:

   1 #处理日期格式,默认输入格式是18/Aug/2008:10:47:23
   2 def getdateformat(para,pformat='%d/%b/%Y:%H:%M:%S',oformat='%Y/%d/%m%H:%M:%S'):
   3    dt=datetime.datetime.strptime(para["localtime"].rstrip(),pformat)
   4    return dt.strftime(oformat)


反馈

创建 by -- ZoomQuiet [2008-08-24 07:01:55]

Name Password4deL ;) :( X-( B-)

PageCommentData