I need to convert a string to a datetime object, along with the fractional seconds. I\'m running into various problems.
Normally, i would do:
>>>
All ancient history by now, but in these modern times you can also conveniently use dateutil
from dateutil import parser as DUp
funky_time_str = "1/1/2011 12:51:00.0123 AM"
foo = DUp.parse(funky_time_str)
print foo.timetuple()
# time.struct_time(tm_year=2011, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=51, tm_sec=0, tm_wday=5, tm_yday=1, tm_isdst=-1)
print foo.microsecond
# 12300
print foo
# 2011-01-01 00:51:00.012300
dateutil
supports a surprising variety of possible input formats, which it parses without pattern strings.