utils.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:amadeuslms 作者: amadeusproject 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号