Discuss / Python / code

船长杰克

#1 Created at ... [Delete] [Delete and Lock User]
def to_timestamp(dt_str, tz_str):
    tz = re.match(r'^UTC([+-]\d{1,2})',tz_str).groups()[0]
    ts = datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S').replace(tzinfo=timezone(timedelta(hours=int(tz))))
    return ts.timestamp()

  • 1

Reply