Is there a Python module for determining the month or day in a string?

Is there a Python module for parsing links for a month or day in a given string?

+5
source share
2 answers

You can try using dateutil.parser, for example:

>>> from dateutil import parser
>>> parser.parse("There a date 09-21 in here", fuzzy=True)
datetime.datetime(2011, 9, 21, 0, 0)

... with the option fuzzy=True. The documentation is here .

+25
source

Are any other characters in the string or just numbers that indicate the date? If you have a date string and want to create a date that you can format, try the following:

import time

time.strptime (datestring,% d.% m.% Y% H:% M:% S ") # e.g., 03/17/2011 10:05:15

You can also create a UNIX timestamp.

timestamp = int(time.mktime(time.strptime(date,"%d.%m.%Y %H:%M:%S")))

,

- , Mark .

0

All Articles