-
TIME ZONE ISSUE
almost 9 years ago
-
over 8 years ago
~~~ Convert UTC To LocalTime
def UTC_To_LocalTime(self, cr, uid, utcdatetime, context): zone = self.pool.get('res.users').browse(cr, uid, uid).tz or 'Asia/Kolkata' from_zone = tz.gettz('UTC') to_zone = tz.gettz(zone) try: utctime = datetime.strptime(utcdatetime, '%Y-%m-%d %H:%M:%S') except: utctime = datetime.strptime(utcdatetime, '%Y-%m-%d') utctimetz = utctime.replace(tzinfo=from_zone) # utctimetz = utctime.replace(tzinfo=to_zone) print 'utctimetz.astimezone(to_zone)',utctimetz.astimezone(to_zone).strftime("%Y-%m-%d %H:%M:%S") return utctimetz.astimezone(to_zone).strftime("%Y-%m-%d %H:%M:%S")
-
1 Answer(s)