import re
from datetime import datetime, timezone, timedelta
def to_timestamp(dt_str,tz_str):
dt_datetime = datetime.strptime(dt_str, '%Y-%m-%d %H:%M:%S')
tz_group = re.match(r'\w{3}(.\d{1,2}):(\d{2})',tz_str)
tz_int = int(tz_group.group(1))
dt_timestamp = dt_datetime.timestamp()
tz_timestamp = tz_int * 3600
finally_timestamp = dt_timestamp - tz_timestamp
return finally_timestamp
因为你在‘dt_timestamp = dt_datetime.timestamp()’的时候,转化为timestamp,没有给出时区,程序应该是默认为北京的时区了,这一步转化会少28800秒,
Sign in to make a reply
蛀牙麻
import re
from datetime import datetime, timezone, timedelta
def to_timestamp(dt_str,tz_str):
dt_datetime = datetime.strptime(dt_str, '%Y-%m-%d %H:%M:%S')
tz_group = re.match(r'\w{3}(.\d{1,2}):(\d{2})',tz_str)
tz_int = int(tz_group.group(1))
dt_timestamp = dt_datetime.timestamp()
tz_timestamp = tz_int * 3600
finally_timestamp = dt_timestamp - tz_timestamp
return finally_timestamp