def timestampFunc(dt_str,tz_str): dt = datetime.strptime(dt_str,"%Y-%m-%d %H:%M:%S") tz = re.split(r'^(UTC|utc)(+|-)(0?[0-9]|1[0-2])\:00$',tz_str) tz = int(tz[2]+tz[3]) print(tz) tz_utc = timezone(timedelta(hours = tz)) dt = dt.replace(tzinfo = tz_utc) timestamps = dt.timestamp() return timestamps
正则表达式,匹配加减号的地方缺少转义符
Sign in to make a reply
花朝zhe
def timestampFunc(dt_str,tz_str): dt = datetime.strptime(dt_str,"%Y-%m-%d %H:%M:%S") tz = re.split(r'^(UTC|utc)(+|-)(0?[0-9]|1[0-2])\:00$',tz_str) tz = int(tz[2]+tz[3]) print(tz) tz_utc = timezone(timedelta(hours = tz)) dt = dt.replace(tzinfo = tz_utc) timestamps = dt.timestamp() return timestamps