Is there a way to check if a time (represented as string) is in the format 'HH:MMa' or 'HH:MMp'?
For example, '12:30p', '11:30a', or '8:30p' could be an input time (where a = am, p = pm).
Thanks!
Is there a way to check if a time (represented as string) is in the format 'HH:MMa' or 'HH:MMp'?
For example, '12:30p', '11:30a', or '8:30p' could be an input time (where a = am, p = pm).
Thanks!
timestring = "11:30a"
import re
pattern = re.compile("^(1[012]|[1-9]):[0-5][0-9][ap]$")
pattern.match(timestring)
A modified version of the code u linked me too
import time
def isTimeFormat(input):
try:
if input[-1] == 'a' or input[-1] == 'p':
time.strptime(input[:-1], '%H:%M')
return True
else:
return False
except ValueError:
return False