Discuss / Python / 作业

作业

Topic source

月半意

#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')
    zone = re.match(r'(UTC)([+-]\d+):(\d+)',tz_str)
    tz = timezone(timedelta(hours=int(zone.group(2))))
    dz_utc = dt.replace(tzinfo=tz)
    return dz_utc.timestamp()

大神的思路最清晰,代码最简洁!学习了


  • 1

Reply