def to_timestamp(dt_str, tz_str):
dt_cform = datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S') #datetime 格式化
tz_value = int(re.match(r'UTC\+?([\-\d]+):',tz_str).group(1)) #match 获取时区转化为数字,re.compile只拿负号,不要加号
tz_delta = timezone(timedelta(hours=tz_value)) #时区差
dt_currunt = dt_cform.replace(tzinfo=tz_delta) #当地时间
return dt_currunt.timestamp() #转timestamp
你这个时区的分钟没有拿到啊,忽略了时区的分钟
Sign in to make a reply
忆往昔念往昔往昔不复悔不当初
def to_timestamp(dt_str, tz_str):
dt_cform = datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S') #datetime 格式化
tz_value = int(re.match(r'UTC\+?([\-\d]+):',tz_str).group(1)) #match 获取时区转化为数字,re.compile只拿负号,不要加号
tz_delta = timezone(timedelta(hours=tz_value)) #时区差
dt_currunt = dt_cform.replace(tzinfo=tz_delta) #当地时间
return dt_currunt.timestamp() #转timestamp