import re from datetime import datetime, timezone, timedelta
def to_timestamp(dt_str, tz_str):
#str转化datetime dt = datetime.strptime(dt_str,'%Y-%m-%d %H:%M:%S') #获取时区 dtutc=int(re.match('UTC([\+\-]\d{1,2}):\d{2}',tz_str).group(1)) #创建时区 utctime=timezone(timedelta(hours=dtutc)) #强制设置时区 utcdt=dt.replace(tzinfo=utctime) #datetime转换为timestamp ts=utcdt.timestamp() return ts
d='2015-1-21 9:01:30' t='UTC+5:00' print(to_timestamp(d,t))
Sign in to make a reply
test_number
import re from datetime import datetime, timezone, timedelta
def to_timestamp(dt_str, tz_str):
d='2015-1-21 9:01:30' t='UTC+5:00' print(to_timestamp(d,t))