判断是不是日期格式,进而方便下一步区分处理:def is_valid_date(strdate): '''判断是否是一个有效的日期字符串''' try: time.strptime(strdate, "%Y-%m-%d") return True except: return False