python - Correctly parse date string with timezone information -


i'm receiving formatted date string via pivotal tracker api: "2012/06/05 17:42:29 cest"

i want convert string utc datetime object, looks python-dateutil not recognize timezone, pytz doesn't know either.

i fear best bet replace cest in string cet, feels wrong. there other way parse summer time strings utc datetime objects couldn't find?

pytz.timezone('cest') # -> pytz.exceptions.unknowntimezoneerror: 'cest' dateutil.parser.parse("2012/06/05 17:42:29 cest") # -> datetime.datetime(2012, 6, 5, 17, 42, 29) 

edit: after thinking again subtracting 1 hour false corresponding timezone in summer time, issue of parsing still stands

there no real cest timezone. use europe/paris, europe/berlin or europe/prague (or one) according region:

>>> pytz.country_timezones('de') [u'europe/berlin']  >>> pytz.country_timezones('fr') [u'europe/paris'] 

they (currently) identical , referring cest in summer.

>>> dateutil.parser.parse("2012/06/05 17:42:29 cest").astimezone(pytz.utc) datetime.datetime(2012, 6, 5, 15, 42, 29, tzinfo=<utc>) 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -