strdate = “2020-1-2 12:1:1”
b = re.findall(":", strdate)
try:
if len(b) >= 2:
time.strptime(strdate, "%Y-%m-%d %H:%M:%S")
# time.strptime(check_date[ck_field], "Y年%m-%d %H:%M:%S")
elif 0 < len(b) < 2:
time.strptime(strdate, "%Y-%m-%d %H:%M")
else:
time.strptime(strdate, "%Y-%m-%d")
except Exception as e:
logger.error(
"字段:{0}>>>>>>>对应值{1}:不是时间格式".format(
check_date[ck_field],
check_date))
Python判断字符串是否符合时间格式
猜你喜欢
转载自blog.csdn.net/qq_34237321/article/details/110090677
今日推荐
周排行