I'm trying to string "20091229050936" to "December 29, 2009 (UTC)"
>>>import time
>>>s = time.strptime("20091229050936", "%Y%m%d%H%M%S") >>>print s.strftime('%H:%M %d %B %Y (UTC)')
give AttributeError: 'time.struct_time' object has no attribute 'strftime'
Obviously, I made a mistake: the wrong time, it is a date-time object! It has a date and time component!
>>>import datetime
>>>s = datetime.strptime("20091229050936", "%Y%m%d%H%M%S")
give AttributeError: 'module' object has no attribute 'strptime'
I mean it is how to convert a string date string formatted?
solution
time.strptime
Return time_struct
; time.strftime
receiving a time_struct
as an optional parameter:
>>>s = time.strptime(page.editTime(), "%Y%m%d%H%M%S") >>>print time.strftime('%H:%M %d %B %Y (UTC)', s)
To the05:09 29 December 2009 (UTC)
article first appeared on Python black hole net , blog sync with the new park