def timechecker(thing):
thing = thing.lower()
thing = thing.replace("now + ","now+")
if ("now+" in thing):
import datetime
thing = thing.replace("now+","")
if ("m" in thing):
thing = thing.replace("m","")
thing = int(thing)
now = datetime.datetime.now()
thing = str(now + datetime.timedelta(minutes = thing))
elif ("h" in thing):
thing = thing.replace("h","")
thing = int(thing)
now = datetime.datetime.now()
thing = str(now + datetime.timedelta(hours = thing))
thing = thing.split(" ")
thing = thing[1]
thing = thing.split(":")
hr = thing[0]
min = thing[1]
thing = hr + ":" + min
if (" am" in thing):
thing = thing.replace(" am"," AM")
if (" pm" in thing):
thing = thing.replace(" pm"," PM")
cck = thing
cck = thing.split(":")
cck = thing[0]
if ((cck > 0) and ("am" not in thing.lower()) and ("pm" not in thing.lower())):
#print ("Given 24hr time. Converting...")
from datetime import datetime
d = datetime.strptime(thing, "%H:%M")
thedate = d.strftime("%-I:%M %p")
else:
thedate = thing
return thedate
评论列表
文章目录