python 判断字符串时间的合法性

​
import datetime
def verify_date_str_lawyer(datetime_str):
    try:        
    	datetime.datetime.strptime(datetime_str, '%Y-%m-%d %H:%M:%S')        
    	return True    
    except ValueError:        
    	return False 
    """%m  01, 02, ..., 12%d  01, 02, ..., 31""" 
print(verify_date_str_lawyer('2003-12-23 23:59:59'))
print(verify_date_str_lawyer('2003-06-30 12:61:52'))

​

 

你可能感兴趣的:(python基础)