Differences between revisions 2 and 3
Revision 2 as of 2009-11-28 15:01:42
Size: 1325
Editor: Elias
Comment: 删除对PageComment2组件的引用
Revision 3 as of 2009-12-25 07:09:16
Size: 1325
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
[[TableOfContents]] <<TableOfContents>>
Line 6: Line 6:
[[Include(ZPyUGnav)]] <<Include(ZPyUGnav)>>
Line 42: Line 42:
创建 by -- ZoomQuiet [[[DateTime(2008-08-24T07:01:55Z)]]] 创建 by -- ZoomQuiet [<<DateTime(2008-08-24T07:01:55Z)>>]

如何将“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]

MiscItems/2008-08-24 (last edited 2009-12-25 07:09:16 by localhost)