plchat/timeconvert.py

15 lines
491 B
Python
Raw Normal View History

2021-04-15 15:16:38 -05:00
from dateutil.parser import *
from dateutil.tz import *
from datetime import *
def utc_to_local(utc, twofourhr=False):
if twofourhr:
clockfmt = '%H:%M'
else:
clockfmt = '%I:%M%p'
time = parse(utc)
local = time.astimezone(tzlocal())
today = datetime.today()
if local.day == today.day and local.month == today.month and local.year == today.year:
return datetime.strftime(local, '%I:%M%p')
return datetime.strftime(local, '%I:%M%p %m-%d-%y')