I'm using python, and want to parsing a string like "01-Jan-1995" to datetime type of python. who can tell me how to do it? thanks.
+2
A:
The standard date()
object in python might be able to parse this sort of date. the dateutil should be even better at parsing this sort of format since you can define custom date formats to parse.
easy_install python-dateutil
to install it.
Soviut
2009-11-11 07:29:34
+1 for python-dateutil. It can even parse datestrings without you having to tell it the format.
unutbu
2009-11-11 18:44:05
+7
A:
On the whole you'd parse date and time strings with the strptime
functions in time
or datetime
modules. Your example could be parsed with:
import datetime
datetime.datetime.strptime("01-Jan-1995", "%d-%b-%Y")
Note that parsing month names is locale-dependent.
Tuure Laurinolli
2009-11-11 07:31:04
A:
Kugel
2009-11-11 07:33:10
A:
If you need to parse natural language date and time strings, consider parsedatetime (and this answer).
Adam Matan
2010-01-06 12:44:50