import re from datetime import datetime, timezone, timedelta def to_timestamp(dt_str, tz_str): dt=datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S') UTC=int(re.match(r'^UTC([-+]*\d{1,2}):00$',tz_str).group(1)) tz_utc=timezone(timedelta(hours=UTC)) lastdt=dt.replace(tzinfo=tz_utc) timestamp=lastdt.timestamp() print(timestamp)
re里边的+-不用转义么
Sign in to make a reply
迷茫的老九