Discuss / Python / 古灵精怪的各种用法,真的容易忘啊

古灵精怪的各种用法,真的容易忘啊

Topic source
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)

31nm

#2 Created at ... [Delete] [Delete and Lock User]

re里边的+-不用转义么


  • 1

Reply