Discuss / Python / 作业

作业

Topic source

EddieLau_

#1 Created at ... [Delete] [Delete and Lock User]
def to_timestamp(dt_str, tz_str):
    # 格式化时间
    dt = datetime.strptime(dt_str, '%Y-%m-%d %H:%M:%S')

    # 获取时区
    reg_tz = re.compile(r'\w+([+|-])(\d+)\:(\d+)')
    sig, h, m = reg_tz.match(tz_str).groups()

    # 重置时区
    dt = dt.replace(tzinfo=timezone(timedelta(hours=int(sig+h), minutes=int(sig+m))))

    return dt.timestamp()

  • 1

Reply