Discuss / Python / 交作业

交作业

Topic source

苏生不语_

#1 Created at ... [Delete] [Delete and Lock User]
def to_timestamp(dt_str, tz_str):
    try:
        m = re.match(r'UTC([+-]\d{1,2}):00', tz_str)
        tzinfo = timezone(timedelta(hours=int(m.group(1))))
        return datetime.strptime(dt_str, '%Y-%m-%d %H:%M:%S').replace(tzinfo=tzinfo).timestamp()
    except Exception as e:
        print(e)
    return None

  • 1

Reply