import re from datetime import datetime, timezone, timedelta
def to_timestamp(dt_str, tz_str): oldtime = datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S') muban = re.compile(r'([a-zA-Z]*)([+,-])([0-9]|0[1-9]|1[0-9]|2[0-4])[:]([0-5][0-9])') jihe = muban.match(tz_str).groups() xiaoshi = int(jihe[1]+jihe[2]) fenzhong = int(jihe[1]+jihe[3]) tz_utc = timezone(timedelta(hours=xiaoshi,minutes=fenzhong)) dt = oldtime.replace(tzinfo=tz_utc) return dt.timestamp()
Sign in to make a reply
天命破凰
import re from datetime import datetime, timezone, timedelta
def to_timestamp(dt_str, tz_str): oldtime = datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S') muban = re.compile(r'([a-zA-Z]*)([+,-])([0-9]|0[1-9]|1[0-9]|2[0-4])[:]([0-5][0-9])') jihe = muban.match(tz_str).groups() xiaoshi = int(jihe[1]+jihe[2]) fenzhong = int(jihe[1]+jihe[3]) tz_utc = timezone(timedelta(hours=xiaoshi,minutes=fenzhong)) dt = oldtime.replace(tzinfo=tz_utc) return dt.timestamp()