Python Convert UTC to Timezone

July 2, 2019
import pytz
import datetime

now_utc = datetime.datetime.utcnow()


tz = pytz.timezone('Asia/Kuala_Lumpur')
now_kl = now_utc.replace(tzinfo=pytz.utc).astimezone(tz)

or

now_kl = pytz.utc.localize(now_utc).astimezone(tz)

or

now_kl = tz.fromutc(now_utc)

Get Local Timezone

import tzlocal

local_tz = tzlocal.get_localzone()
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.