Discuss / Python / 作业

作业

Topic source

小样还逃

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

想不到更漂亮的办法了。。。

def to_timestamp(dt_str,tz_str):
    dt = datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S')
    M = re.match('UTC([+-]\d+):(\d{2})',tz_str)
    tz = timezone(timedelta(hours=int(M.group(1)),minutes=int(M.group(2))))
    return dt.replace(tzinfo=tz).timestamp()

  • 1

Reply