3

I'm trying to parse a string to a date object on Google App Engine. The string is formatted locally and I thereby either need to set the locale setting before parsing the string or find a third part module that does international formatting. In Google App Engine I found that only the "C" locale is supported, which made my initial implementation useless:

datestring = "20. oktober 2013, 18:43"

locale.setlocale(locale.LC_ALL, 'da_DK.UTF-8')

date = datetime.datetime.strptime(datestring, "%d. %B %Y, %H:%M")

Threw error:

Error: locale emulation only supports "C" locale

In my search for a third part module I found Babel. It has formatting features from data objects to string but I can't see that it works the other way around, and I can't find another module that does the trick.

Is there any other solution I haven't thought of, or do I need to go make my own module for this?

Thanks!

TJ-
  • 116
  • 10
  • Do you really want to parse that datetime format anyway? If it is an API input, you should force the implementation to send an ISO 8601 formatted string. If it comes from an html form or something similar, you should use a datetime picker. If you really need to parse this format, a good module for parsing multiple datetime formats is iso8601 (https://pypi.python.org/pypi/iso8601). – Remco Haszing Dec 05 '13 at 17:27

0 Answers0