Discuss / Python / 作业

作业

Topic source
def to_timestamp(dt_str, tz_str):
    cday = datetime.strptime(dt_str, '%Y-%m-%d %H:%M:%S') #读入日期时间
    tz = re.match(r'\w+.(.*?):', tz_str).group(1)   # 读入时区
    if re.match(r'UTC(.)', tz_str).group(1) == '-': #判断时区加减
        tz = int(tz)
    else:
        tz = -int(tz)
    now = cday + timedelta(hours=tz+8)              #timestamp是用本地时间转换,所以这里转成本地时间
    return now.timestamp()

  • 1

Reply