How do I strtotime in python?
Try this:
For use with the datetime module
, documentation here
>>>import datetime
>>>a = u'11/5/2003'
>>>time1 = datetime.datetime.strptime(a, "%m/%d/%Y")
>>>print time1
datetime.datetime(2003, 11, 5, 0, 0)
In ipython
:
In [1]: import datetime
In [2]: a = u'11/5/2003'
In [3]: time1 = datetime.datetime.strptime(a, "%m/%d/%Y")
In [4]: print time1
2003-11-05 00:00:00
Use with the time module
, documentation here
>>>import time
>>>a = u'11/5/2003'
>>>time1 = time.strptime(a, "%m/%d/%Y")
>>>print time1
time.struct_time(tm_year=2003, tm_mon=11, tm_mday=5, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=309, tm_isdst=-1)
strptime()
is definitely the right approach, it's just a class method for the datetime
class (confusingly part of the datetime
module).
That is, datetime.datetime.strptime()
is what you're looking for (and not datetime.strptime()
.