Discuss / Python / 五八

五八

Topic source

Mx

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

def to_timestamp(dt_str, tz_str):

    std=datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S')

    retz=re.compile(r'^UTC([\+\-]?[\d]+)(\:00$)')

    tz_utc = timezone(timedelta(hours=int(retz.match(tz_str).group(1))))

    dt = std.replace(tzinfo=tz_utc)

    return dt.timestamp()


  • 1

Reply