console.py 文件源码

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

项目:esmcheckds2 作者: andywalden 项目源码 文件源码
def _get_time_obj(time_str):
    """
    In some ESM versions the time format is YYYY/MM/DD instead of
    DD/MM/YYYY. This detects and normalizes to the latter.

    Args:
        last_time (str): timestamp in format 'YYYY/MM/DD HH:MM:SS' 
                         or 'DD/MM/YYYY HH:MM:SS'

    Returns:
        str of timestamp in 'DD/MM/YYYY HH:MM:SS' format 
            or None if neither format matches
    """
    time_format1 = '%m/%d/%Y %H:%M:%S'
    time_format2 = '%Y/%m/%d %H:%M:%S'

    try: 
        time_obj = datetime.strptime(time_str, time_format1)
    except ValueError:
        try:
            time_obj = datetime.strptime(time_str, time_format2)
        except ValueError:
            logging.debug('Invalid time format: {}'.format(time_str))
            time_obj = None
    return time_obj
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号