I’d like to know if there is a function which returns True if a string is in “hh:mm” hour format?
I can write my own function, but it would be good if there is a standard function.
Best Regards
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just try to interpret it using the
timemodule, and catch theValueErrorraised when the conversion fails:The only thing this doesn’t check is that you actually specify the correct number of digits. Checking if
len(time_string) == 5might be simple enough to check that.Edit: inspired by Kimvais in the comments; to wrap it as a function: