strptime for different languages
Ulrich Goebel
ml at fam-goebel.de
Tue Dec 17 05:37:34 EST 2019
Hi,
I need to interpret a date string to get a datetime object. That should
be done with strptime from the module datetime.
But I don't know enough about the locale settings from where the date
sting comes. Actually the date_string cames from different contact forms
inside websites made by different content management systems. So it could be
13. Januar 1965
13. January 1965
13.01.1965
1965-01-13
or even some known other formats.
What I tried is a cascade of try's:
try:
d = strptime(date_string, format_string_1)
except:
try:
d = strptime(date_string, format_string_2)
except:
try:
d = strptime(date_string, format_string_3)
except:
...
That works, as long the month comes as number.
But how to cover name of months in different language?
(Shure, it would not be possible to cover all possibilities and
languages. But I know the possible languages.)
Best regards
Ulrich
--
Ulrich Goebel
Am Büchel 57, 53173 Bonn
More information about the Python-list
mailing list