利用正则表达式判断是否时间格式 def func(string): return True if( re.match("^(([0-1]\d)|(2[0-4])):[0-5]\d$", string) ) is not None else False