def strToDate(string):
correct_format = formats.get_format("SHORT_DATE_FORMAT")
correct_format = correct_format.split('/')
correct_format = ["%" + x for x in correct_format]
slash_format = '/'.join(correct_format)
hiphen_format = '-'.join(correct_format)
try:
search_date = datetime.strptime(string, slash_format)
search_date = timezone.make_aware(search_date, timezone.get_current_timezone())
except ValueError:
try:
search_date = datetime.strptime(string, hiphen_format)
search_date = timezone.make_aware(search_date, timezone.get_current_timezone())
except ValueError:
search_date = datetime.fromtimestamp(0)
return search_date
评论列表
文章目录