Discuss / Python / 还是会忘记,需要经常用才能熟悉

还是会忘记,需要经常用才能熟悉

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

  • 1

Reply