可以处理半个时区
Topic sourceUTC符号当为负时,UTC-1:30
def to_timestamp(dt_str, tz_str):
dt = datetime.strptime(dt_str, '%Y-%m-%d %H:%M:%S')
match = re.match(r'UTC([\+\-])(\d+):(\d+)', tz_str)
if match:
h = int(match.group(1) + match.group(2))
m = int(match.group(1) + match.group(3))
tz = timezone(timedelta(hours = h , minutes = m))
dt = dt.replace(tzinfo= tz)
return dt.timestamp()
- 1
cacaty
def to_timestamp(dt_str, tz_str):
dt = datetime.strptime(dt_str, '%Y-%m-%d %H:%M:%S')
match = re.match(r'UTC([\+\-]\d+):(\d+)', tz_str)
if match:
h = int(match.group(1))
m = int(match.group(2))
tz = timezone(timedelta(hours = h , minutes = m))
dt = dt.replace(tzinfo= tz)
return dt.timestamp()