Converting Timezone in Python (12-Hour Format)

from datetime import datetime from pytz import timezone format = '%Y-%m-%d %I:%M:%S %p %Z%z' # UTC time now_utc = datetime.now(timezone('UTC')) print(now_utc.strftime(format)) # 2021-04-13 06:14:05 AM UTC+0000 # WIB time now_jkt = now_utc.astimezone(timezone('Asia/Jakarta')) print(now_jkt.strftime(format)) # 2021-04-13 01:14:05 PM WIB+0700 # Format: # https://www.w3schools.com/python/python_datetime.asp

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.