How to create tzinfo when I have UTC offset?

With Python 3.2 or higher, you can do this using the builtin datetime library:

import datetime
datetime.timezone(-datetime.timedelta(hours=5, minutes=30)

To solve your specific problem, you could use regex:

sign, hours, minutes = re.match('([+\-]?)(\d{2})(\d{2})', '+0530').groups()
sign = -1 if sign == '-' else 1
hours, minutes = int(hours), int(minute)

tzinfo = datetime.timezone(sign * datetime.timedelta(hours=hours, minutes=minutes))
datetime.datetime(2013, 2, 3, 9, 45, tzinfo=tzinfo)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)