Discuss / Python / 练习

练习

Topic source
def to_timestamp(dt_str, tz_str):
    dt = datetime.strptime(dt_str, '%Y-%m-%d %H:%M:%S')
    hour = re.match(r'\w+([\+-]\d+)\:\d+', tz_str).group(1)
    tz = timezone(timedelta(hours=int(hour)))
    dt = dt.replace(tzinfo=tz)
    return dt.timestamp()

  • 1

Reply