Convert GMT based time to UTC python -


i date 2014/08/19 03:38:46 gmt-4 database.

how convert utc formatted date in python?

ps: use python 2.6.6

having non-naive datetime object, should invoke astimezone method desired timezone

>>> import pytz >>> dateutil import parser # dateutil.parser datetime object string, ensure non-naive datetime >>> parser.parse('2014/08/19 03:38:46 gmt-4') datetime.datetime(2014, 8, 19, 3, 38, 46, tzinfo=tzoffset(none, 14400)) >>> dt = parser.parse('2014/08/19 03:38:46 gmt-4') >>> dt.astimezone (pytz.utc) datetime.datetime(2014, 8, 18, 23, 38, 46, tzinfo=<utc>) 

you right in comment, utc time should go behind, while think solution, this

>>> dt = parser.parse('2014/08/19 03:38:46 gmt-4') >>> dt.replace(tzinfo=pytz.utc) + dt.tzinfo._offset datetime.datetime(2014, 8, 19, 7, 38, 46, tzinfo=<utc>) 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -