Hi,
I have a date as a string in the form „dd/mm/yyyy“ and need to convert it to the form „dd. MMMM yyyy“ so that the verbose month is printed out in German.
Now, because we still have the locale bug in Pythonista ...
>>> import locale
>>> locale.setlocale(locale.LC_ALL, 'de')
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/var/containers/Bundle/Application/4D653312-79ED-4473-B63A-522E9EA8C250/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/locale.py", line 599, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
>>> locale.setlocale(locale.LC_ALL, 'de_DE')
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/var/containers/Bundle/Application/4D653312-79ED-4473-B63A-522E9EA8C250/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/locale.py", line 599, in setlocale
return _setlocale(category, locale)
locale.Error: unsupported locale setting
... I guess I‘m forced to find a workaround. So I opted for the objc_util module and tried this (variable gebDatum holds the initial date string in the above mentioned format):
from objc_util import *
NSDateFormatter = ObjCClass('NSDateFormatter')
dateFormatter = NSDateFormatter.alloc().init()
NSLocale = ObjCClass('NSLocale')
deLocale = NSLocale.alloc().initWithLocaleIdentifier_(ns('de'))
dateFormatter.setLocale_(deLocale)
NSDate = ObjCClass('NSDate')
date = NSDate.alloc().init()
dateFormatter.setDateFormat_('dd/MM/yyyy')
date = dateFormatter.dateFromString_(gebDatum)
dateFormatter.setDateFormat_('dd. MMMM yyyy')
gebDatumVerbose = dateFormatter.stringFromDate_(date)
Now when I want to print out the variable gebDatumVerbose I get the error must be str, not ObjCInstance.
Any help / hint / explanation / other (shorter) solution for my problem?
Thanks a lot!
Stefan.