def to_timestap(t_str,tz_str):
result=re.match(r'UTC[\W](\d)[\W](\d){2}',tz_str)
h=result.group(1) # 时
m=result.group(2) # 分
tzone=timezone(timedelta(hours=int(h),minutes=int(m))) # 用户时区
time_user=datetime.strptime(t_str,'%Y-%m-%d %H:%M:%S').replace(tzinfo=tzone) # 将用户输入的时间设置用户的时区
timestap_user=time_user.timestamp() # 再将用户时区的时间转换为timestamp
print(timestap_user)
to_timestap('2015-1-21 9:01:30','UTC+5:00')
Sign in to make a reply
懒懒的小懒
def to_timestap(t_str,tz_str):
result=re.match(r'UTC[\W](\d)[\W](\d){2}',tz_str)
h=result.group(1) # 时
m=result.group(2) # 分
tzone=timezone(timedelta(hours=int(h),minutes=int(m))) # 用户时区
time_user=datetime.strptime(t_str,'%Y-%m-%d %H:%M:%S').replace(tzinfo=tzone) # 将用户输入的时间设置用户的时区
timestap_user=time_user.timestamp() # 再将用户时区的时间转换为timestamp
print(timestap_user)
to_timestap('2015-1-21 9:01:30','UTC+5:00')